'Google Map freezing in flutter
when I integrate google map in flutter, the first once I launch the screen that contains google map widget it freezes my app. note I'm using tab view widget and google map is the third tab in my app.
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`
});
}
}
Solution 1:[1]
The code you've shared seems to loop on configuring GoogleMapController inside setState(). This causes the map to be rebuilt multiple times. You don't need to call setState() to configure GoogleMapController. It's also demonstrated on google_maps_flutter plugin's sample.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Omatt |
