当我将Google Map集成到Flutter中时,第一次启动包含Google Map小部件的屏幕时,它会冻结我的应用程序。 请注意,我使用的是标签视图小部件,而Google地图是我应用中的第三个标签。
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'dart:async';
class MapModlue extends StatefulWidget {
@override
State createState() => MapModlueState();
}
class MapModlueState extends State<MapModlue> {
GoogleMapController mapController;
double opacity = 0.0;
@override
Widget build(BuildContext context) {
return Container(
padding: new EdgeInsets.all(0.0),
decoration:
new BoxDecoration(color: Color.fromRGBO(240, 240, 240, 1.0)),
child: Opacity(
opacity: opacity,
child: GoogleMap(
onMapCreated: _onMapCreated,
)));
}
// ignore: invalid_override
void _onMapCreated(GoogleMapController controller) {
Timer _timer = new Timer(const Duration(milliseconds: 400), () {
// this timer to hide black screen that appear before map loading
setState(() {
mapController = controller;
opacity = 1.0;
});`enter code here`
});
}
}