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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// SPDX-License-Identifier: Apache-2.0
import 'dart:async';
import 'dart:math';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:latlong2/latlong.dart';
// -------------------------------------------------------------
final clockProvider = StateNotifierProvider<Clock, DateTime>((ref) {
return Clock();
});
class Clock extends StateNotifier<DateTime> {
late final Timer _timer;
Clock() : super(DateTime.now()) {
_timer = Timer.periodic(const Duration(seconds: 5), (_) {
state = DateTime.now();
});
}
@override
void dispose() {
_timer.cancel();
super.dispose();
}
}
// -------------------------------------------------------------
class PolyLinesDB {
final List<LatLng> currPolyLineList;
final List<LatLng> polyLineList;
PolyLinesDB({required this.currPolyLineList, required this.polyLineList});
PolyLinesDB copyWith({
List<LatLng>? currPolyLineList,
List<LatLng>? polyLineList,
}) {
return PolyLinesDB(
currPolyLineList: currPolyLineList ?? this.currPolyLineList,
polyLineList: polyLineList ?? this.polyLineList,
);
}
}
class PolyLineNotifier extends StateNotifier<PolyLinesDB> {
static final PolyLinesDB initialvalue = PolyLinesDB(
currPolyLineList: [],
polyLineList: [],
);
PolyLineNotifier() : super(initialvalue);
void update({
List<LatLng>? currPolyLineList,
List<LatLng>? polyLineList,
}) {
state = state.copyWith(
currPolyLineList: currPolyLineList,
polyLineList: polyLineList,
);
}
}
final polyLineStateProvider =
StateNotifierProvider<PolyLineNotifier, PolyLinesDB>(
(ref) => PolyLineNotifier(),
);
// -------------------------------------------------------------
class Gear {
static String parking = "P";
static String drive = "D";
static String neutral = "N";
static String reverse = "R";
}
double calculateDistance(point1, point2) {
double p = 0.017453292519943295;
double halfCosLatDiff = cos((point2.latitude - point1.latitude) * p) / 2;
double halfCosLngDiff = cos((point2.longitude - point1.longitude) * p) / 2;
double dist = 0.5 - halfCosLatDiff + cos(point1.latitude * p) * cos(point2.latitude * p) * (0.5 - halfCosLngDiff);
return 12742 * asin(sqrt(dist));
}
|