Skip to content

Instantly share code, notes, and snippets.

@MarcinusX
Created April 30, 2020 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcinusX/97230719f58e6835b0761f369d88b608 to your computer and use it in GitHub Desktop.
Save MarcinusX/97230719f58e6835b0761f369d88b608 to your computer and use it in GitHub Desktop.
/// Copied from https://github.com/flutter/flutter/issues/33988#issuecomment-600748507
/// Steps to reproduce:
/// 1. Move the map location, bool value keeps changing.
/// 2. Tap on the container anywhere.
/// 3. Now again move the map.
/// 4. bool value does not change.(onCameraIdle() not working).
/// Occurs on google_maps_flutter:0.5.27
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
void main() => runApp(MyHomePage());
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
GoogleMapController mapController;
final LatLng _center = const LatLng(45.521563, -122.677433);
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
}
bool isCameraMoving;
@override
void initState() {
super.initState();
isCameraMoving = false;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Maps POC App'),
),
body: Stack(
children: <Widget>[
GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
onCameraMove: (CameraPosition cameraPosition) {
setState(() {
isCameraMoving = true;
});
},
onCameraIdle: () {
setState(() {
isCameraMoving = false;
});
},
),
Positioned(
top: 0,
left: 0,
right: 0,
child: Padding(
padding: const EdgeInsets.all(24.0),
child: Container(
alignment: Alignment.center,
color: Colors.cyan,
height: 200,
child: Text(
'Camera moving: $isCameraMoving',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 24, color: Colors.white),
),
),
),
)
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment