From 1ebd1f22f28e8b2139b04756da163c6f79c5f42b Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Wed, 29 Apr 2020 13:51:17 +0900 Subject: [PATCH] removed useless googlemap init workaround --- .../fullscreen/info/location_section.dart | 42 ++++++------ .../fullscreen/info/map_initializer.dart | 65 ------------------- 2 files changed, 20 insertions(+), 87 deletions(-) delete mode 100644 lib/widgets/fullscreen/info/map_initializer.dart diff --git a/lib/widgets/fullscreen/info/location_section.dart b/lib/widgets/fullscreen/info/location_section.dart index eb82b25ae..19043e4dc 100644 --- a/lib/widgets/fullscreen/info/location_section.dart +++ b/lib/widgets/fullscreen/info/location_section.dart @@ -7,7 +7,6 @@ import 'package:aves/utils/geo_utils.dart'; import 'package:aves/widgets/common/aves_filter_chip.dart'; import 'package:aves/widgets/common/icons.dart'; import 'package:aves/widgets/fullscreen/info/info_page.dart'; -import 'package:aves/widgets/fullscreen/info/map_initializer.dart'; import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:outline_material_icons/outline_material_icons.dart'; @@ -182,28 +181,27 @@ class ImageMapState extends State with AutomaticKeepAliveClientMixin { child: Container( color: Colors.white70, height: 200, - child: GoogleMapInitializer( - builder: (context) => GoogleMap( - initialCameraPosition: CameraPosition( - target: widget.latLng, - zoom: widget.initialZoom, - ), - onMapCreated: (controller) => setState(() => _controller = controller), - rotateGesturesEnabled: false, - scrollGesturesEnabled: false, - zoomControlsEnabled: false, - zoomGesturesEnabled: false, - tiltGesturesEnabled: false, - myLocationEnabled: false, - myLocationButtonEnabled: false, - markers: { - Marker( - markerId: MarkerId(widget.markerId), - icon: BitmapDescriptor.defaultMarkerWithHue(accentHue), - position: widget.latLng, - ) - }, + child: GoogleMap( + // GoogleMap init perf issue: https://github.com/flutter/flutter/issues/28493 + initialCameraPosition: CameraPosition( + target: widget.latLng, + zoom: widget.initialZoom, ), + onMapCreated: (controller) => setState(() => _controller = controller), + rotateGesturesEnabled: false, + scrollGesturesEnabled: false, + zoomControlsEnabled: false, + zoomGesturesEnabled: false, + tiltGesturesEnabled: false, + myLocationEnabled: false, + myLocationButtonEnabled: false, + markers: { + Marker( + markerId: MarkerId(widget.markerId), + icon: BitmapDescriptor.defaultMarkerWithHue(accentHue), + position: widget.latLng, + ) + }, ), ), ), diff --git a/lib/widgets/fullscreen/info/map_initializer.dart b/lib/widgets/fullscreen/info/map_initializer.dart deleted file mode 100644 index afbda561b..000000000 --- a/lib/widgets/fullscreen/info/map_initializer.dart +++ /dev/null @@ -1,65 +0,0 @@ -import 'dart:async'; - -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter/widgets.dart'; -import 'package:google_maps_flutter/google_maps_flutter.dart'; -import 'package:meta/meta.dart'; - -// workaround to Google Maps initialization blocking the dart thread -// cf https://github.com/flutter/flutter/issues/28493 -// it loads first Google Maps in an isolate, and then build the desired map - -class GoogleMapInitializer extends StatefulWidget { - final WidgetBuilder builder, errorBuilder, placeholderBuilder; - - const GoogleMapInitializer({ - @required this.builder, - this.errorBuilder, - this.placeholderBuilder, - }); - - @override - _GoogleMapInitializerState createState() => _GoogleMapInitializerState(); -} - -class _GoogleMapInitializerState extends State { - Future initializer; - - @override - void initState() { - super.initState(); - initializer = compute(_preload, null); - } - - @override - Widget build(BuildContext context) { - return FutureBuilder( - future: initializer, - builder: (context, snapshot) { - if (snapshot.hasError) { - return widget.errorBuilder?.call(context) ?? const Icon(Icons.error_outline); - } else if (snapshot.connectionState == ConnectionState.done) { - return widget.builder(context); - } else { - return widget.placeholderBuilder?.call(context) ?? const SizedBox.shrink(); - } - }); - } -} - -Future _preload(_) async { - final mapCreatedCompleter = Completer(); - GoogleMap( - compassEnabled: false, - mapToolbarEnabled: false, - rotateGesturesEnabled: false, - scrollGesturesEnabled: false, - zoomGesturesEnabled: false, - tiltGesturesEnabled: false, - buildingsEnabled: false, - initialCameraPosition: const CameraPosition(target: LatLng(0, 0), zoom: 20), - onMapCreated: (controller) => mapCreatedCompleter.complete(), - ); - return mapCreatedCompleter.future; -}