diff options
author | Aakash Solanki <tech2aks@gmail.com> | 2022-08-31 15:23:53 +0200 |
---|---|---|
committer | Aakash Solanki <tech2aks@gmail.com> | 2022-09-14 11:50:03 +0200 |
commit | e39f2a69fde316b4e260c151757fb739494fbd56 (patch) | |
tree | 3ea8a65eee101457264d0000b5bcf122d428b0b8 /lib/provider.dart | |
parent | 5957cfa0609ff57adfafa4538fb151d00f3c72e3 (diff) |
Upload Flutter Instrument Cluster app
Instrument Cluster demo app which shows speedometer
tachometer guages, temperature and fuel bars and some
indicators like turn indicators, engine malfunction,
lights, cruise control, lane assist. KUKSA.VAL is the
data source for the widgets.
This app depends on several plugins and all the plugins
have an OSI-approved license.
Bug-AGL: SPEC-4543
Change-Id: I2698c66f9d8d824690ae7e567ca7c93ceeb17e08
Signed-off-by: Aakash Solanki <tech2aks@gmail.com>
Diffstat (limited to 'lib/provider.dart')
-rw-r--r-- | lib/provider.dart | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/provider.dart b/lib/provider.dart new file mode 100644 index 0000000..c96c8e4 --- /dev/null +++ b/lib/provider.dart @@ -0,0 +1,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));
+}
|