From 3da9465b1ecdf34f3c5d98fc2105694e81113894 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Fri, 9 Aug 2019 22:59:31 +0900 Subject: [PATCH] info: keep google map alive --- lib/model/image_entry.dart | 2 +- lib/widgets/fullscreen/info_page.dart | 66 +++++++++++++++++---------- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/lib/model/image_entry.dart b/lib/model/image_entry.dart index 981d92509..6bad9a0d2 100644 --- a/lib/model/image_entry.dart +++ b/lib/model/image_entry.dart @@ -135,6 +135,6 @@ class CatalogMetadata { @override String toString() { - return 'CatalogMetadata{contentId: $contentId, dateMillis: $dateMillis, latitude: $latitude, longitude: $longitude, xmpSubjects=$xmpSubjects}'; + return 'CatalogMetadata{contentId=$contentId, dateMillis=$dateMillis, latitude=$latitude, longitude=$longitude, xmpSubjects=$xmpSubjects}'; } } diff --git a/lib/widgets/fullscreen/info_page.dart b/lib/widgets/fullscreen/info_page.dart index 6bf7edd3b..037da8fe0 100644 --- a/lib/widgets/fullscreen/info_page.dart +++ b/lib/widgets/fullscreen/info_page.dart @@ -37,7 +37,7 @@ class InfoPageState extends State { } initMetadataLoader() { - _catalogLoader = MetadataService.getCatalogMetadata(entry.contentId, entry.path);//.then(addAddressToMetadata); + _catalogLoader = MetadataService.getCatalogMetadata(entry.contentId, entry.path).then(addAddressToMetadata); _metadataLoader = MetadataService.getAllMetadata(entry.path); } @@ -155,30 +155,9 @@ class InfoPageState extends State { List _buildLocationSection(double latitude, double longitude, Address address) { if (latitude == null || longitude == null) return []; - final latLng = LatLng(latitude, longitude); return [ SectionRow('Location'), - SizedBox( - height: 200, - child: ClipRRect( - borderRadius: BorderRadius.all( - Radius.circular(16), - ), - child: GoogleMap( - initialCameraPosition: CameraPosition( - target: latLng, - zoom: 12, - ), - markers: [ - Marker( - markerId: MarkerId(entry.path), - icon: BitmapDescriptor.defaultMarker, - position: latLng, - ) - ].toSet(), - ), - ), - ), + ImageMap(markerId: entry.path, latLng: LatLng(latitude, longitude)), if (address != null) Padding( padding: EdgeInsets.only(top: 8), @@ -208,6 +187,47 @@ class InfoPageState extends State { } } +class ImageMap extends StatefulWidget { + final String markerId; + final LatLng latLng; + + const ImageMap({Key key, this.markerId, this.latLng}) : super(key: key); + + @override + State createState() => ImageMapState(); +} + +class ImageMapState extends State with AutomaticKeepAliveClientMixin { + @override + Widget build(BuildContext context) { + super.build(context); + return SizedBox( + height: 200, + child: ClipRRect( + borderRadius: BorderRadius.all( + Radius.circular(16), + ), + child: GoogleMap( + initialCameraPosition: CameraPosition( + target: widget.latLng, + zoom: 12, + ), + markers: [ + Marker( + markerId: MarkerId(widget.markerId), + icon: BitmapDescriptor.defaultMarker, + position: widget.latLng, + ) + ].toSet(), + ), + ), + ); + } + + @override + bool get wantKeepAlive => true; +} + class SectionRow extends StatelessWidget { final String title;