Aspas
Aspas

Reputation: 11

what is meaning of GoogleMapController in flutter?

I'm new to flutter so this question sounds like foolish but I really want this meaning.

  1. What is going on in the code after onMapCreated?
  2. What value is being passed to the controller?
  3. What the difference between controller and _controller?
class MapSample extends StatefulWidget {
  @override
  State<MapSample> createState() => MapSampleState();
}
class MapSampleState extends State<MapSample> {
  Completer<GoogleMapController> _controller = Completer();
...

@override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: GoogleMap(
        mapType: MapType.hybrid,
        initialCameraPosition: _kGooglePlex,
        onMapCreated: (controller) {
          _controller.complete(controller);
        },
      ),);
  }

Upvotes: 0

Views: 1095

Answers (1)

Usman Akhlaq
Usman Akhlaq

Reputation: 531

1: onMapCreated is a function that takes a mapController and optional parameter called options. The option is used to change the UI of the map such as rotation gestures, zoom gestures, map type, etc. The function of mapController is mostly similar to TextEditingController as it is being used to manage the camera functions, zoom and animations, etc.

2: As mentioned above mapController takes parameters to change the functions of the map such as changing position, zoom, etc.

3: The difference between controller and _controller is that _controller is private to the class where it is declared and can not be accessed outside of it. It is the same concept of private and public variables.

Upvotes: 3

Related Questions