removed useless googlemap init workaround
This commit is contained in:
parent
b1d662a1b8
commit
1ebd1f22f2
2 changed files with 20 additions and 87 deletions
|
@ -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/aves_filter_chip.dart';
|
||||||
import 'package:aves/widgets/common/icons.dart';
|
import 'package:aves/widgets/common/icons.dart';
|
||||||
import 'package:aves/widgets/fullscreen/info/info_page.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:flutter/material.dart';
|
||||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||||
import 'package:outline_material_icons/outline_material_icons.dart';
|
import 'package:outline_material_icons/outline_material_icons.dart';
|
||||||
|
@ -182,8 +181,8 @@ class ImageMapState extends State<ImageMap> with AutomaticKeepAliveClientMixin {
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Colors.white70,
|
color: Colors.white70,
|
||||||
height: 200,
|
height: 200,
|
||||||
child: GoogleMapInitializer(
|
child: GoogleMap(
|
||||||
builder: (context) => GoogleMap(
|
// GoogleMap init perf issue: https://github.com/flutter/flutter/issues/28493
|
||||||
initialCameraPosition: CameraPosition(
|
initialCameraPosition: CameraPosition(
|
||||||
target: widget.latLng,
|
target: widget.latLng,
|
||||||
zoom: widget.initialZoom,
|
zoom: widget.initialZoom,
|
||||||
|
@ -208,7 +207,6 @@ class ImageMapState extends State<ImageMap> with AutomaticKeepAliveClientMixin {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Column(children: [
|
Column(children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
|
|
|
@ -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<GoogleMapInitializer> {
|
|
||||||
Future<void> 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<void> _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;
|
|
||||||
}
|
|
Loading…
Reference in a new issue