-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is now possible to take snapshots of the displayed map. Fixes #25
- Loading branch information
luis
authored and
luis
committed
Jul 1, 2021
1 parent
572d215
commit 30bc3ea
Showing
4 changed files
with
107 additions
and
1 deletion.
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
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,71 @@ | ||
// 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:apple_maps_flutter_example/page.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:apple_maps_flutter/apple_maps_flutter.dart'; | ||
|
||
const CameraPosition _kInitialPosition = | ||
CameraPosition(target: LatLng(-33.852, 151.211), zoom: 11.0); | ||
|
||
class SnapshotPage extends ExamplePage { | ||
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> { | ||
AppleMapController? _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: AppleMap( | ||
onMapCreated: onMapCreated, | ||
initialCameraPosition: _kInitialPosition, | ||
), | ||
), | ||
TextButton( | ||
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(AppleMapController 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