From 9ba227f63a5f83055910b502ca90bb523950c77b Mon Sep 17 00:00:00 2001 From: Scott Murray Date: Sat, 31 Dec 2022 00:34:31 -0500 Subject: 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 Change-Id: Ibe1ff26f8cd95cbe9cbb477feaf31c9f4919bf6a --- lib/vehicle-signals/vehicle_config.dart | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/vehicle-signals/vehicle_config.dart (limited to 'lib/vehicle-signals/vehicle_config.dart') diff --git a/lib/vehicle-signals/vehicle_config.dart b/lib/vehicle-signals/vehicle_config.dart new file mode 100644 index 0000000..59682c4 --- /dev/null +++ b/lib/vehicle-signals/vehicle_config.dart @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 +import 'dart:convert'; +import 'dart:io'; + +import 'package:dashboard_app/config.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:http/http.dart' as http; + + + +final sockConnectprovider = FutureProvider.family( + (ref, client) => connect(client,ref)); + + + +Future initializeClient() async { + + + SecurityContext ctx = SecurityContext.defaultContext; + + HttpClient client = HttpClient(context: ctx) + ..findProxy = null + ..badCertificateCallback = (cert, host, port) { + return true; + }; + return client; +} + + + +Future connect(HttpClient client, ref) async { + final config = ref.read(ConfigStateprovider); + WebSocket socket = await WebSocket.connect( + "wss://${config.hostname}:${config.port}", + customClient: client); + return socket; +} + + -- cgit 1.2.3-korg