-
Notifications
You must be signed in to change notification settings - Fork 7
/
rotate.dart
63 lines (56 loc) · 1.53 KB
/
rotate.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import 'package:flutter/material.dart';
import 'package:universe/universe.dart';
class RotateControllerMap extends StatefulWidget {
const RotateControllerMap({super.key});
@override
State<RotateControllerMap> createState() => _RotateControllerMapState();
}
class _RotateControllerMapState extends State<RotateControllerMap> {
final _mapKey = UniqueKey();
final _mapController = MapController();
@override
void dispose() {
_mapController.dispose();
super.dispose();
}
void _rotate90() {
_mapController.rotate(90, animate: true, onAnimateEnd: () {
if (mounted) setState(() {});
});
}
void _rotateBack() {
_mapController.rotate(0, animate: true, onAnimateEnd: () {
if (mounted) setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Stack(
children: [
U.OpenStreetMap(
key: _mapKey,
controller: _mapController,
center: [51.555158, -0.108343],
zoom: 15,
),
Positioned(
left: 20,
bottom: 90,
child: ElevatedButton(
onPressed:
_mapController.rotation == 90.0 ? _rotateBack : _rotate90,
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: Colors.lightBlue,
),
child: Text(
_mapController.rotation == 90.0
? 'Rotate Back'
: 'Rotate 90 degrees',
),
),
),
],
);
}
}