| // Copyright 2013 The Flutter Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // ignore_for_file: public_member_api_docs |
| |
| import 'dart:async'; |
| |
| import 'package:flutter/material.dart'; |
| import 'package:google_maps_flutter/google_maps_flutter.dart'; |
| |
| void main() => runApp(const MyApp()); |
| |
| class MyApp extends StatelessWidget { |
| const MyApp({Key? key}) : super(key: key); |
| |
| @override |
| Widget build(BuildContext context) { |
| return const MaterialApp( |
| title: 'Flutter Google Maps Demo', |
| home: MapSample(), |
| ); |
| } |
| } |
| |
| // #docregion MapSample |
| class MapSample extends StatefulWidget { |
| const MapSample({Key? key}) : super(key: key); |
| |
| @override |
| State<MapSample> createState() => MapSampleState(); |
| } |
| |
| class MapSampleState extends State<MapSample> { |
| final Completer<GoogleMapController> _controller = |
| Completer<GoogleMapController>(); |
| |
| static const CameraPosition _kGooglePlex = CameraPosition( |
| target: LatLng(37.42796133580664, -122.085749655962), |
| zoom: 14.4746, |
| ); |
| |
| static const CameraPosition _kLake = CameraPosition( |
| bearing: 192.8334901395799, |
| target: LatLng(37.43296265331129, -122.08832357078792), |
| tilt: 59.440717697143555, |
| zoom: 19.151926040649414); |
| |
| @override |
| Widget build(BuildContext context) { |
| return Scaffold( |
| body: GoogleMap( |
| mapType: MapType.hybrid, |
| initialCameraPosition: _kGooglePlex, |
| onMapCreated: (GoogleMapController controller) { |
| _controller.complete(controller); |
| }, |
| ), |
| floatingActionButton: FloatingActionButton.extended( |
| onPressed: _goToTheLake, |
| label: const Text('To the lake!'), |
| icon: const Icon(Icons.directions_boat), |
| ), |
| ); |
| } |
| |
| Future<void> _goToTheLake() async { |
| final GoogleMapController controller = await _controller.future; |
| controller.animateCamera(CameraUpdate.newCameraPosition(_kLake)); |
| } |
| } |
| // #enddocregion MapSample |