blob: fbc7ae2a3e24a7448ab49c2e3ae1e4bdc0a0baeb [file] [log] [blame]
// 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:typed_data';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'page.dart';
const CameraPosition _kInitialPosition =
CameraPosition(target: LatLng(-33.852, 151.211), zoom: 11.0);
class SnapshotPage extends GoogleMapExampleAppPage {
const SnapshotPage({Key? key})
: super(const Icon(Icons.camera_alt), 'Take a snapshot of the map',
key: key);
@override
Widget build(BuildContext context) {
return _SnapshotBody();
}
}
class _SnapshotBody extends StatefulWidget {
@override
_SnapshotBodyState createState() => _SnapshotBodyState();
}
class _SnapshotBodyState extends State<_SnapshotBody> {
GoogleMapController? _mapController;
Uint8List? _imageBytes;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
SizedBox(
height: 180,
child: GoogleMap(
onMapCreated: onMapCreated,
initialCameraPosition: _kInitialPosition,
),
),
TextButton(
child: const Text('Take a snapshot'),
onPressed: () async {
final Uint8List? imageBytes =
await _mapController?.takeSnapshot();
setState(() {
_imageBytes = imageBytes;
});
},
),
Container(
decoration: BoxDecoration(color: Colors.blueGrey[50]),
height: 180,
child: _imageBytes != null ? Image.memory(_imageBytes!) : null,
),
],
),
);
}
// ignore: use_setters_to_change_properties
void onMapCreated(GoogleMapController controller) {
_mapController = controller;
}
}