minor fixes

This commit is contained in:
Thibault Deckers 2021-10-07 15:55:55 +09:00
parent 5338cb47c2
commit c63de86c78
12 changed files with 40 additions and 11 deletions

View file

@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:io';
import 'package:aves/geo/countries.dart'; import 'package:aves/geo/countries.dart';
import 'package:aves/model/entry_cache.dart'; import 'package:aves/model/entry_cache.dart';
@ -178,6 +179,8 @@ class AvesEntry {
return _extension; return _extension;
} }
bool get isMissingAtPath => path != null && !File(path!).existsSync();
// the MIME type reported by the Media Store is unreliable // the MIME type reported by the Media Store is unreliable
// so we use the one found during cataloguing if possible // so we use the one found during cataloguing if possible
String get mimeType => _catalogMetadata?.mimeType ?? sourceMimeType; String get mimeType => _catalogMetadata?.mimeType ?? sourceMimeType;

View file

@ -40,8 +40,10 @@ class PlatformMetadataFetchService implements MetadataFetchService {
}); });
if (result != null) return result as Map; if (result != null) return result as Map;
} on PlatformException catch (e, stack) { } on PlatformException catch (e, stack) {
if (!entry.isMissingAtPath) {
await reportService.recordError(e, stack); await reportService.recordError(e, stack);
} }
}
return {}; return {};
} }
@ -118,8 +120,10 @@ class PlatformMetadataFetchService implements MetadataFetchService {
} }
return MultiPageInfo.fromPageMaps(entry, pageMaps); return MultiPageInfo.fromPageMaps(entry, pageMaps);
} on PlatformException catch (e, stack) { } on PlatformException catch (e, stack) {
if (!entry.isMissingAtPath) {
await reportService.recordError(e, stack); await reportService.recordError(e, stack);
} }
}
return null; return null;
} }

View file

@ -348,7 +348,7 @@ class _CollectionAppBarState extends State<CollectionAppBar> with SingleTickerPr
// we compute the default name beforehand // we compute the default name beforehand
// because some filter labels need localization // because some filter labels need localization
final sortedFilters = List<CollectionFilter>.from(filters)..sort(); final sortedFilters = List<CollectionFilter>.from(filters)..sort();
defaultName = sortedFilters.first.getLabel(context); defaultName = sortedFilters.first.getLabel(context).replaceAll('\n', ' ');
} }
final result = await showDialog<Tuple2<AvesEntry?, String>>( final result = await showDialog<Tuple2<AvesEntry?, String>>(
context: context, context: context,

View file

@ -57,7 +57,7 @@ class GeoMap extends StatefulWidget {
} }
class _GeoMapState extends State<GeoMap> { class _GeoMapState extends State<GeoMap> {
// as of google_maps_flutter v2.0.6, Google Maps initialization is blocking // as of google_maps_flutter v2.0.6, Google map initialization is blocking
// cf https://github.com/flutter/flutter/issues/28493 // cf https://github.com/flutter/flutter/issues/28493
// it is especially severe the first time, but still significant afterwards // it is especially severe the first time, but still significant afterwards
// so we prevent loading it while scrolling or animating // so we prevent loading it while scrolling or animating
@ -68,14 +68,21 @@ class _GeoMapState extends State<GeoMap> {
List<AvesEntry> get entries => widget.entries; List<AvesEntry> get entries => widget.entries;
// cap initial zoom to avoid a zoom change
// when toggling overlay on Google map initial state
static const double minInitialZoom = 3;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
final initialEntry = widget.initialEntry; final initialEntry = widget.initialEntry;
final points = (initialEntry != null ? [initialEntry] : entries).map((v) => v.latLng!).toSet(); final points = (initialEntry != null ? [initialEntry] : entries).map((v) => v.latLng!).toSet();
_boundsNotifier = ValueNotifier(ZoomedBounds.fromPoints( final bounds = ZoomedBounds.fromPoints(
points: points.isNotEmpty ? points : {Constants.wonders[Random().nextInt(Constants.wonders.length)]}, points: points.isNotEmpty ? points : {Constants.wonders[Random().nextInt(Constants.wonders.length)]},
collocationZoom: settings.infoMapZoom, collocationZoom: settings.infoMapZoom,
);
_boundsNotifier = ValueNotifier(bounds.copyWith(
zoom: max(bounds.zoom, minInitialZoom),
)); ));
_defaultMarkerCluster = _buildFluster(); _defaultMarkerCluster = _buildFluster();
} }

View file

@ -109,7 +109,7 @@ class _EntryGoogleMapState extends State<EntryGoogleMap> with WidgetsBindingObse
case AppLifecycleState.detached: case AppLifecycleState.detached:
break; break;
case AppLifecycleState.resumed: case AppLifecycleState.resumed:
// workaround for blank Google Maps when resuming app // workaround for blank Google map when resuming app
// cf https://github.com/flutter/flutter/issues/40284 // cf https://github.com/flutter/flutter/issues/40284
_googleMapController?.setMapStyle(null); _googleMapController?.setMapStyle(null);
break; break;

View file

@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
// generate bitmap from widget, for Google Maps // generate bitmap from widget, for Google map
class MarkerGeneratorWidget<T extends Key> extends StatefulWidget { class MarkerGeneratorWidget<T extends Key> extends StatefulWidget {
final List<Widget> markers; final List<Widget> markers;
final bool Function(T markerKey) isReadyToRender; final bool Function(T markerKey) isReadyToRender;

View file

@ -66,7 +66,7 @@ class _EntryLeafletMapState extends State<EntryLeafletMap> with TickerProviderSt
ZoomedBounds get bounds => boundsNotifier.value; ZoomedBounds get bounds => boundsNotifier.value;
// duration should match the uncustomizable Google Maps duration // duration should match the uncustomizable Google map duration
static const _cameraAnimationDuration = Duration(milliseconds: 600); static const _cameraAnimationDuration = Duration(milliseconds: 600);
@override @override

View file

@ -39,7 +39,7 @@ class ImageMarker extends StatelessWidget {
) )
: const SizedBox(); : const SizedBox();
// need to be sized for the Google Maps marker generator // need to be sized for the Google map marker generator
child = SizedBox( child = SizedBox(
width: extent, width: extent,
height: extent, height: extent,

View file

@ -63,5 +63,19 @@ class ZoomedBounds extends Equatable {
); );
} }
ZoomedBounds copyWith({
LatLng? sw,
LatLng? ne,
double? zoom,
double? rotation,
}) {
return ZoomedBounds(
sw: sw ?? this.sw,
ne: ne ?? this.ne,
zoom: zoom ?? this.zoom,
rotation: rotation ?? this.rotation,
);
}
bool contains(LatLng point) => GeoUtils.contains(sw, ne, point); bool contains(LatLng point) => GeoUtils.contains(sw, ne, point);
} }

View file

@ -110,7 +110,7 @@ class _AddressRowState extends State<_AddressRow> {
child: Container( child: Container(
alignment: AlignmentDirectional.centerStart, alignment: AlignmentDirectional.centerStart,
// addresses can include non-latin scripts with inconsistent line height, // addresses can include non-latin scripts with inconsistent line height,
// which is especially an issue for relayout/painting of heavy Google maps, // which is especially an issue for relayout/painting of heavy Google map,
// so we give extra height to give breathing room to the text and stabilize layout // so we give extra height to give breathing room to the text and stabilize layout
height: Theme.of(context).textTheme.bodyText2!.fontSize! * context.select<MediaQueryData, double>((mq) => mq.textScaleFactor) * 2, height: Theme.of(context).textTheme.bodyText2!.fontSize! * context.select<MediaQueryData, double>((mq) => mq.textScaleFactor) * 2,
child: ValueListenableBuilder<String?>( child: ValueListenableBuilder<String?>(

View file

@ -382,7 +382,7 @@ class _MapPageContentState extends State<MapPageContent> with SingleTickerProvid
void _toggleOverlay() => _overlayVisible.value = !_overlayVisible.value; void _toggleOverlay() => _overlayVisible.value = !_overlayVisible.value;
// TODO TLAD [map] as of Flutter v2.5.1 / google_maps_flutter v2.0.10, toggling overlay changes the size of the map, which is an issue for Google Maps on Android 12 // TODO TLAD [map] as of Flutter v2.5.1 / google_maps_flutter v2.0.10, toggling overlay changes the size of the map, which is an issue for Google map on Android 12
// cf https://github.com/flutter/flutter/issues/90556 // cf https://github.com/flutter/flutter/issues/90556
Future<void> _onOverlayVisibleChange({bool animate = true}) async { Future<void> _onOverlayVisibleChange({bool animate = true}) async {
if (_overlayVisible.value) { if (_overlayVisible.value) {

View file

@ -68,6 +68,7 @@ class ViewerDebugPage extends StatelessWidget {
'sourceTitle': entry.sourceTitle ?? '', 'sourceTitle': entry.sourceTitle ?? '',
'sourceMimeType': entry.sourceMimeType, 'sourceMimeType': entry.sourceMimeType,
'mimeType': entry.mimeType, 'mimeType': entry.mimeType,
'isMissingAtPath': '${entry.isMissingAtPath}',
}, },
), ),
const Divider(), const Divider(),