diff --git a/lib/widgets/fullscreen/info/info_page.dart b/lib/widgets/fullscreen/info/info_page.dart index 11cdeeead..34fa7dec8 100644 --- a/lib/widgets/fullscreen/info/info_page.dart +++ b/lib/widgets/fullscreen/info/info_page.dart @@ -80,7 +80,13 @@ class InfoPageState extends State { children: [ Expanded(child: BasicSection(entry: entry)), const SizedBox(width: 8), - Expanded(child: LocationSection(entry: entry, showTitle: false)), + Expanded( + child: LocationSection( + entry: entry, + showTitle: false, + visibleNotifier: widget.visibleNotifier, + ), + ), ], ), ), @@ -92,7 +98,11 @@ class InfoPageState extends State { delegate: SliverChildListDelegate( [ BasicSection(entry: entry), - LocationSection(entry: entry, showTitle: true), + LocationSection( + entry: entry, + showTitle: true, + visibleNotifier: widget.visibleNotifier, + ), ], ), ), diff --git a/lib/widgets/fullscreen/info/location_section.dart b/lib/widgets/fullscreen/info/location_section.dart index 4a0336fb1..2ae2ab99f 100644 --- a/lib/widgets/fullscreen/info/location_section.dart +++ b/lib/widgets/fullscreen/info/location_section.dart @@ -6,50 +6,94 @@ import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:outline_material_icons/outline_material_icons.dart'; -class LocationSection extends AnimatedWidget { +class LocationSection extends StatefulWidget { final ImageEntry entry; final bool showTitle; + final ValueNotifier visibleNotifier; - LocationSection({ + const LocationSection({ Key key, @required this.entry, @required this.showTitle, - }) : super( - key: key, - listenable: Listenable.merge([ - entry.metadataChangeNotifier, - entry.addressChangeNotifier, - ])); + @required this.visibleNotifier, + }) : super(key: key); + + @override + _LocationSectionState createState() => _LocationSectionState(); +} + +class _LocationSectionState extends State { + String _loadedUri; + + ImageEntry get entry => widget.entry; + + @override + void initState() { + super.initState(); + _registerWidget(widget); + } + + @override + void didUpdateWidget(LocationSection oldWidget) { + super.didUpdateWidget(oldWidget); + _unregisterWidget(oldWidget); + _registerWidget(widget); + } + + @override + void dispose() { + _unregisterWidget(widget); + super.dispose(); + } + + void _registerWidget(LocationSection widget) { + entry.metadataChangeNotifier.addListener(_handleChange); + entry.addressChangeNotifier.addListener(_handleChange); + widget.visibleNotifier.addListener(_handleChange); + } + + void _unregisterWidget(LocationSection widget) { + entry.metadataChangeNotifier.removeListener(_handleChange); + entry.addressChangeNotifier.removeListener(_handleChange); + widget.visibleNotifier.removeListener(_handleChange); + } @override Widget build(BuildContext context) { - return !entry.hasGps - ? const SizedBox.shrink() - : Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (showTitle) - const Padding( - padding: EdgeInsets.only(bottom: 8), - child: SectionRow('Location'), - ), - ImageMap( - markerId: entry.path, - latLng: LatLng( - entry.latLng.item1, - entry.latLng.item2, - ), - geoUri: entry.geoUri, - initialZoom: settings.infoMapZoom, - ), - if (entry.isLocated) - Padding( - padding: const EdgeInsets.only(top: 8), - child: InfoRow('Address', entry.addressDetails.addressLine), - ), - ], - ); + final showMap = (_loadedUri == entry.uri) || (entry.hasGps && widget.visibleNotifier.value); + if (showMap) { + _loadedUri = entry.uri; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (widget.showTitle) + const Padding( + padding: EdgeInsets.only(bottom: 8), + child: SectionRow('Location'), + ), + ImageMap( + markerId: entry.path, + latLng: LatLng( + entry.latLng.item1, + entry.latLng.item2, + ), + geoUri: entry.geoUri, + initialZoom: settings.infoMapZoom, + ), + if (entry.isLocated) + Padding( + padding: const EdgeInsets.only(top: 8), + child: InfoRow('Address', entry.addressDetails.addressLine), + ), + ], + ); + } else { + _loadedUri = null; + return const SizedBox.shrink(); + } } + + void _handleChange() => setState(() {}); } class ImageMap extends StatefulWidget { diff --git a/lib/widgets/fullscreen/info/metadata_section.dart b/lib/widgets/fullscreen/info/metadata_section.dart index be3b16952..af900cdeb 100644 --- a/lib/widgets/fullscreen/info/metadata_section.dart +++ b/lib/widgets/fullscreen/info/metadata_section.dart @@ -17,7 +17,7 @@ class MetadataSectionSliver extends StatefulWidget { const MetadataSectionSliver({ @required this.entry, @required this.columnCount, - this.visibleNotifier, + @required this.visibleNotifier, }); @override