From 4fbd3fdb9e01c197d972b78961f0d033534a5cc7 Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Wed, 28 Dec 2022 15:05:26 -0500 Subject: Add volume control to bottom panel Changes: - Import a reworked version of the KUKSA.val client code from the Flutter dashboard app, with the aggregated signal Riverpod provider replaced with per-signal providers for the signal the homescreen needs and a couple of temperature ones it might use. Using separate providers is more in-line with recommended Riverpod best practices. - Various tweaks to enable using Riverpod. - Split the bottom panel out into its own widget, and add a stack in it to layer the default logo panel with the volume control slider, which has been added as a new widget definition to provide the hook to drive timer based lowering behavior like the Qt homescreen does. - The KUKSA.val connection widget has been added to the bottom panel rather than overriding the top-level widget as in the dashboard and HVAC apps. This seems preferable with respect to still providing some functionality in the event KUKSA.val is unavailable. - Remove the old demo dashboard and HVAC pages that are now unused, along with the image assets they needed, to allow cleaning up pubspec.yaml and ease maintenance. Bug-AGL: SPEC-4659 Signed-off-by: Scott Murray Change-Id: I5d9180a3461948a58321564e71134c4961ce0ef7 --- lib/vehicle-signals/viss_connected_widget.dart | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/vehicle-signals/viss_connected_widget.dart (limited to 'lib/vehicle-signals/viss_connected_widget.dart') diff --git a/lib/vehicle-signals/viss_connected_widget.dart b/lib/vehicle-signals/viss_connected_widget.dart new file mode 100644 index 0000000..dd3e4aa --- /dev/null +++ b/lib/vehicle-signals/viss_connected_widget.dart @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: Apache-2.0 +import 'dart:async'; +import 'dart:io'; + +import 'package:flutter_homescreen/vehicle-signals/viss_config.dart'; +import 'package:flutter_homescreen/vehicle-signals/viss_methods.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_homescreen/vehicle-signals/vss_providers.dart'; + +class VISServerConnectedWidget extends ConsumerStatefulWidget { + const VISServerConnectedWidget( + {Key? key, required this.client, required this.socket}) + : super(key: key); + final WebSocket socket; + final HttpClient client; + + @override + ConsumerState createState() => + _VISServerConnectedWidgetState(); +} + +class _VISServerConnectedWidgetState + extends ConsumerState { + late Timer _timer; + + void _updateSocket() { + ref.read(VISServerSocketProvider.notifier).update(widget.socket); + } + + @override + void initState() { + super.initState(); + VISS.init(widget.socket, ref); + Future.delayed(Duration.zero, () => _updateSocket()); + _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 Container(); + } +} -- cgit 1.2.3-korg