main.dart
void main() => runApp(DemoApp()); class DemoApp extends StatelessWidget { const DemoApp(); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text("Using Geolocator"), ), body: const Center( child: GPSWidget(), ) ), ); } }
gps_widget.dart
class GPSWidget extends StatelessWidget { static final _stream = getPositionStream(); const GPSWidget(); @override Widget build(BuildContext context) { return Wrap( spacing: 20, direction: Axis.vertical, crossAxisAlignment: WrapCrossAlignment.center, children: <Widget>[ SvgPicture.asset( "assets/geolocate.svg", height: 70, ), StreamBuilder<Position>( stream: _stream, builder: (context, positionData) { if (positionData.hasData) { final data = positionData.data; if (data != null) { final lat = data.latitude.toStringAsFixed(5); final lon = data.longitude.toStringAsFixed(5); return Text("$lat | $lon"); } else { return const Text("No data available."); } } return const CircularProgressIndicator(); }, ) ], ); } }
This website and the book are not official Google products. No affiliations are involved. Built with Java 14 and Vert.X
"Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC"