2023-12-22 21:23:24 +08:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
import 'package:amap_map/amap_map.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2023-12-30 07:54:59 +08:00
|
|
|
class SnapshotPage extends StatefulWidget {
|
2023-12-22 21:23:24 +08:00
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _SnapShotState();
|
|
|
|
}
|
|
|
|
|
2023-12-30 07:54:59 +08:00
|
|
|
class _SnapShotState extends State<SnapshotPage> {
|
2023-12-22 21:23:24 +08:00
|
|
|
AMapController? _mapController;
|
|
|
|
Uint8List? _imageBytes;
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: AMapWidget(
|
|
|
|
onMapCreated: _onMapCreated,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 10, bottom: 10),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 40,
|
|
|
|
width: 100,
|
|
|
|
child: TextButton(
|
|
|
|
child: Text('截屏'),
|
|
|
|
style: ButtonStyle(
|
2024-08-26 09:55:49 +08:00
|
|
|
shape: WidgetStateProperty.all(RoundedRectangleBorder(
|
2023-12-22 21:23:24 +08:00
|
|
|
borderRadius: BorderRadius.circular(10))),
|
|
|
|
//文字颜色
|
2024-08-26 09:55:49 +08:00
|
|
|
foregroundColor: WidgetStateProperty.all(Colors.white),
|
2023-12-22 21:23:24 +08:00
|
|
|
//水波纹颜色
|
2024-08-26 09:55:49 +08:00
|
|
|
overlayColor: WidgetStateProperty.all(Colors.blueAccent),
|
2023-12-22 21:23:24 +08:00
|
|
|
//背景颜色
|
2024-08-26 09:55:49 +08:00
|
|
|
backgroundColor: WidgetStateProperty.resolveWith((states) {
|
2023-12-22 21:23:24 +08:00
|
|
|
//设置按下时的背景颜色
|
2024-08-26 09:55:49 +08:00
|
|
|
if (states.contains(WidgetState.pressed)) {
|
2023-12-22 21:23:24 +08:00
|
|
|
return Colors.blueAccent;
|
|
|
|
}
|
|
|
|
//默认背景颜色
|
|
|
|
return Colors.blue;
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
final imageBytes = await _mapController?.takeSnapshot();
|
|
|
|
setState(() {
|
|
|
|
_imageBytes = imageBytes;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(color: Colors.blueGrey[50]),
|
|
|
|
child: _imageBytes != null ? Image.memory(_imageBytes!) : null,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onMapCreated(AMapController controller) {
|
|
|
|
_mapController = controller;
|
|
|
|
}
|
|
|
|
}
|