-
-
Notifications
You must be signed in to change notification settings - Fork 896
Expand file tree
/
Copy pathtest_marker.dart
More file actions
63 lines (54 loc) · 1.61 KB
/
test_marker.dart
File metadata and controls
63 lines (54 loc) · 1.61 KB
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 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:latlong2/latlong.dart';
final _randomGenerator = Random(10);
class TestMarker extends StatefulWidget {
const TestMarker({super.key, required this.point});
final LatLng point;
@override
State<TestMarker> createState() => _TestMarkerState();
}
class _TestMarkerState extends State<TestMarker> {
Timer? _tapSelected;
bool _hoverSelected = false;
bool get _isSelected => _tapSelected != null || _hoverSelected;
late final _unselectedColor = Color.fromARGB(
255,
_randomGenerator.nextInt(256),
_randomGenerator.nextInt(256),
_randomGenerator.nextInt(256),
);
@override
Widget build(BuildContext context) {
print('built ${widget.point}');
return DecoratedBox(
decoration: BoxDecoration(
border: Border.all(
color: _isSelected ? Colors.green : Colors.black.withAlpha(51),
width: _isSelected ? 3 : 1,
),
),
child: MouseRegion(
onEnter: (_) => setState(() => _hoverSelected = true),
onExit: (_) => setState(() => _hoverSelected = false),
child: GestureDetector(
onTap: () => setState(() {
_tapSelected?.cancel();
_tapSelected = Timer(
const Duration(seconds: 1),
() {
if (mounted) setState(() => _tapSelected = null);
},
);
}),
child: Icon(
Icons.location_pin,
size: 40,
color: _isSelected ? Colors.green : _unselectedColor,
),
),
),
);
}
}