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/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<ImageMap> 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,
|
||||
)
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -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