This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[google_maps_flutter] Take snapshot of map (#2607)
- Loading branch information
Showing
9 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/google_maps_flutter/google_maps_flutter/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/google_maps_flutter/google_maps_flutter/example/lib/snapshot.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2020 The Chromium 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 Page { | ||
SnapshotPage() | ||
: super(const Icon(Icons.camera_alt), 'Take a snapshot of the map'); | ||
|
||
@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: [ | ||
SizedBox( | ||
height: 180, | ||
child: GoogleMap( | ||
onMapCreated: onMapCreated, | ||
initialCameraPosition: _kInitialPosition, | ||
), | ||
), | ||
FlatButton( | ||
child: Text('Take a snapshot'), | ||
onPressed: () async { | ||
final imageBytes = await _mapController?.takeSnapshot(); | ||
setState(() { | ||
_imageBytes = imageBytes; | ||
}); | ||
}, | ||
), | ||
Container( | ||
decoration: BoxDecoration(color: Colors.blueGrey[50]), | ||
height: 180, | ||
child: _imageBytes != null ? Image.memory(_imageBytes) : null, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
|
||
void onMapCreated(GoogleMapController controller) { | ||
_mapController = controller; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters