summaryrefslogtreecommitdiffstats
path: root/lib/vehicle-signals/onBoarding_page.dart
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2022-12-31 00:34:31 -0500
committerScott Murray <scott.murray@konsulko.com>2022-12-31 06:50:16 +0000
commit9ba227f63a5f83055910b502ca90bb523950c77b (patch)
treee8dc553cf3b9264c4081f1bb76a95dd7be2f5afc /lib/vehicle-signals/onBoarding_page.dart
parent7e9b0b78a48b4fb26996d67a07277f86b69e18ed (diff)
Rework Riverpod provider usage
Replace the single Riverpod provider for all vehicle signals with separate ones for each required signal used directly in the widgets that require them. This is more in line with recommended Riverpod practice, and should avoids driving full widget tree rebuilds on every signal received. Bug-AGL: SPEC-4660 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: Ibe1ff26f8cd95cbe9cbb477feaf31c9f4919bf6a
Diffstat (limited to 'lib/vehicle-signals/onBoarding_page.dart')
-rw-r--r--lib/vehicle-signals/onBoarding_page.dart61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/vehicle-signals/onBoarding_page.dart b/lib/vehicle-signals/onBoarding_page.dart
new file mode 100644
index 0000000..6009c54
--- /dev/null
+++ b/lib/vehicle-signals/onBoarding_page.dart
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: Apache-2.0
+import 'dart:async';
+import 'dart:io';
+
+import 'package:dashboard_app/vehicle-signals/vehicle_config.dart';
+import 'package:dashboard_app/vehicle-signals/vehicle_methods.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+
+import '../HomePage.dart';
+
+class OnBoardingPage extends ConsumerStatefulWidget {
+ const OnBoardingPage({Key? key, required this.client, required this.socket})
+ : super(key: key);
+ final WebSocket socket;
+ final HttpClient client;
+
+ @override
+ ConsumerState<OnBoardingPage> createState() => _OnBoardingPageState();
+}
+
+class _OnBoardingPageState extends ConsumerState<OnBoardingPage> {
+ late Timer _timer;
+
+
+ @override
+ void initState() {
+ super.initState();
+ VISS.init(widget.socket,ref);
+ _timer = Timer.periodic(const Duration(seconds: 2), (timer) {
+
+ if (widget.socket.readyState == 3) {
+ ref.refresh(sockConnectprovider(widget.client));
+ }
+ });
+ WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
+ widget.socket.listen(
+ (data) {
+ VISS.parseData(ref, data);
+
+ },
+ onError: (e, stk) {
+ print(e.toString());
+ ref.refresh(sockConnectprovider(widget.client));
+ },
+ );
+ });
+ }
+
+ @override
+ void dispose() {
+ super.dispose();
+ _timer.cancel();
+ widget.socket.close(786887, "Connection lost with server!");
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return const HomePage();
+ }
+} \ No newline at end of file