From 3502b19bdba983d0020e3ef61529951e046c4197 Mon Sep 17 00:00:00 2001 From: Codel1417 Date: Fri, 20 Dec 2024 20:28:18 -0500 Subject: [PATCH] update many deprecated methods --- .../Definitions/Device/device_definition.dart | 16 ++++++++----- lib/Backend/action_registry.dart | 9 ++++---- lib/Backend/app_shortcuts.dart | 5 ++-- lib/Backend/device_registry.dart | 15 ++++++------ lib/Backend/firmware_update.dart | 9 ++++---- lib/Backend/move_lists.dart | 6 ++--- lib/Backend/sensors.dart | 6 ++--- lib/Backend/wear_bridge.dart | 7 +++--- lib/Frontend/Widgets/manage_gear.dart | 23 ++++++++++++++++--- lib/Frontend/Widgets/tail_blog.dart | 2 +- lib/Frontend/pages/action_selector.dart | 2 +- lib/Frontend/pages/actions.dart | 6 ++--- lib/Frontend/pages/home.dart | 2 +- lib/Frontend/pages/intro.dart | 4 ++-- lib/Frontend/pages/triggers.dart | 4 ++-- 15 files changed, 70 insertions(+), 46 deletions(-) diff --git a/lib/Backend/Definitions/Device/device_definition.dart b/lib/Backend/Definitions/Device/device_definition.dart index 614bd292..319b90cf 100644 --- a/lib/Backend/Definitions/Device/device_definition.dart +++ b/lib/Backend/Definitions/Device/device_definition.dart @@ -123,7 +123,7 @@ enum DeviceState { standby, runAction, busy } enum GlowtipStatus { glowtip, noGlowtip, unknown } -enum tailControlStatus { tailControl, legacy, unknown } +enum TailControlStatus { tailControl, legacy, unknown } @freezed class BluetoothUartService with _$BluetoothUartService { @@ -131,6 +131,7 @@ class BluetoothUartService with _$BluetoothUartService { required String bleDeviceService, required String bleRxCharacteristic, required String bleTxCharacteristic, + required String label, }) = _BluetoothUartService; } @@ -139,17 +140,20 @@ final List uartServices = const [ bleDeviceService: "3af2108b-d066-42da-a7d4-55648fa0a9b6", bleRxCharacteristic: "c6612b64-0087-4974-939e-68968ef294b0", bleTxCharacteristic: "5bfd6484-ddee-4723-bfe6-b653372bbfd6", + label: "Legacy Gear", ), BluetoothUartService( bleDeviceService: "927dee04-ddd4-4582-8e42-69dc9fbfae66", bleRxCharacteristic: "0b646a19-371e-4327-b169-9632d56c0e84", bleTxCharacteristic: "05e026d8-b395-4416-9f8a-c00d6c3781b9", + label: "Legacy Ears", ), // TailCoNTROL uuids BluetoothUartService( bleDeviceService: "19f8ade2-d0c6-4c0a-912a-30601d9b3060", bleRxCharacteristic: "567a99d6-a442-4ac0-b676-4993bf95f805", bleTxCharacteristic: "5e4d86ac-ef2f-466f-a857-8776d45ffbc2", + label: "TailCoNTROL", ), ]; @@ -184,7 +188,7 @@ class BaseStatefulDevice { final ValueNotifier gearConfigInfo = ValueNotifier(GearConfigInfo()); final ValueNotifier fwInfo = ValueNotifier(null); final ValueNotifier hasUpdate = ValueNotifier(false); - final ValueNotifier isTailCoNTROL = ValueNotifier(tailControlStatus.unknown); + final ValueNotifier isTailCoNTROL = ValueNotifier(TailControlStatus.unknown); late final Stream rxCharacteristicStream; late final CommandQueue commandQueue; @@ -228,7 +232,7 @@ class BaseStatefulDevice { bluetoothUartService.addListener( () { if (bluetoothUartService.value == null) { - isTailCoNTROL.value = tailControlStatus.unknown; + isTailCoNTROL.value = TailControlStatus.unknown; return; } @@ -236,8 +240,8 @@ class BaseStatefulDevice { uartServices.firstWhere( (element) => element.bleDeviceService.toLowerCase() == "19f8ade2-d0c6-4c0a-912a-30601d9b3060", ) - ? tailControlStatus.tailControl - : tailControlStatus.legacy; + ? TailControlStatus.tailControl + : TailControlStatus.legacy; }, ); } @@ -260,7 +264,7 @@ class BaseStatefulDevice { stopWatch.reset(); mtu.value = -1; mandatoryOtaRequired.value = false; - isTailCoNTROL.value = tailControlStatus.unknown; + isTailCoNTROL.value = TailControlStatus.unknown; bluetoothUartService.value = null; } } diff --git a/lib/Backend/action_registry.dart b/lib/Backend/action_registry.dart index 2a751934..f1bf5afc 100644 --- a/lib/Backend/action_registry.dart +++ b/lib/Backend/action_registry.dart @@ -1,6 +1,7 @@ import 'package:built_collection/built_collection.dart'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'Bluetooth/bluetooth_manager.dart'; @@ -300,13 +301,13 @@ class GetAvailableActions extends _$GetAvailableActions { if (baseAction.deviceCategory.contains(baseStatefulDevice.baseDeviceDefinition.deviceType) && ((baseAction.actionCategory == ActionCategory.glowtip && baseStatefulDevice.hasGlowtip.value == GlowtipStatus.glowtip) || baseAction.actionCategory != ActionCategory.glowtip)) { // Handle migrating ears to unified firmware if (baseAction.deviceCategory.contains(DeviceType.ears) && baseStatefulDevice.baseDeviceDefinition.deviceType == DeviceType.ears) { - if (baseStatefulDevice.isTailCoNTROL.value == tailControlStatus.tailControl) { + if (baseStatefulDevice.isTailCoNTROL.value == TailControlStatus.tailControl) { // skip legacy moves if (baseAction is EarsMoveList) { continue; } // skip unified moves for legacy firmware ears - } else if (baseStatefulDevice.isTailCoNTROL.value == tailControlStatus.legacy) { + } else if (baseStatefulDevice.isTailCoNTROL.value == TailControlStatus.legacy) { if (baseAction is CommandAction) { continue; } @@ -339,7 +340,7 @@ class GetAvailableActions extends _$GetAvailableActions { } @Riverpod(keepAlive: true) -BuiltMap> getAllActions(GetAllActionsRef ref) { +BuiltMap> getAllActions(Ref ref) { Map> sortedActions = {}; final BuiltList moveLists = ref.watch(moveListsProvider); final BuiltList audioActions = ref.watch(userAudioActionsProvider); @@ -366,7 +367,7 @@ BuiltMap> getAllActions(GetAllActionsRef re } @Riverpod(keepAlive: true) -BaseAction? getActionFromUUID(GetActionFromUUIDRef ref, String? uuid) { +BaseAction? getActionFromUUID(Ref ref, String? uuid) { if (uuid == null) { return null; } diff --git a/lib/Backend/app_shortcuts.dart b/lib/Backend/app_shortcuts.dart index 0cba00e9..53a28ad4 100644 --- a/lib/Backend/app_shortcuts.dart +++ b/lib/Backend/app_shortcuts.dart @@ -1,5 +1,4 @@ import 'package:built_collection/built_collection.dart'; -import 'package:collection/collection.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:quick_actions/quick_actions.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; @@ -16,7 +15,7 @@ part 'app_shortcuts.g.dart'; const QuickActions quickActions = QuickActions(); @Riverpod(keepAlive: true) -Future appShortcuts(AppShortcutsRef ref) async { +Future appShortcuts(Ref ref) async { await Future.delayed(const Duration(seconds: 5)); quickActions.initialize((shortcutType) { BaseAction? action = ref.read(getActionFromUUIDProvider(shortcutType)); @@ -35,7 +34,7 @@ Future updateShortcuts(BuiltList favoriteActions, Ref ref) .map( (e) => ref.read(getActionFromUUIDProvider(e.actionUUID)), ) - .whereNotNull(); + .nonNulls; quickActions.setShortcutItems( allActions diff --git a/lib/Backend/device_registry.dart b/lib/Backend/device_registry.dart index 64751975..abe269c4 100644 --- a/lib/Backend/device_registry.dart +++ b/lib/Backend/device_registry.dart @@ -1,5 +1,6 @@ import 'package:built_collection/built_collection.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:logging/logging.dart' as log; import 'package:riverpod_annotation/riverpod_annotation.dart'; @@ -74,7 +75,7 @@ class DeviceRegistry { } @Riverpod(keepAlive: true) -BuiltSet getByAction(GetByActionRef ref, BaseAction baseAction) { +BuiltSet getByAction(Ref ref, BaseAction baseAction) { deviceRegistryLogger.info("Getting devices for action::$baseAction"); Set foundDevices = {}; final BuiltList watch = ref.watch(getAvailableIdleGearProvider); @@ -109,7 +110,7 @@ class GetAvailableIdleGear extends _$GetAvailableIdleGear { } @Riverpod(keepAlive: true) -BuiltSet getAvailableGearTypes(GetAvailableGearTypesRef ref) { +BuiltSet getAvailableGearTypes(Ref ref) { final BuiltList watch = ref.watch(getAvailableGearProvider); return watch .map( @@ -119,13 +120,13 @@ BuiltSet getAvailableGearTypes(GetAvailableGearTypesRef ref) { } @Riverpod(keepAlive: true) -BuiltList getAvailableIdleGearForAction(GetAvailableIdleGearForActionRef ref, BaseAction baseAction) { +BuiltList getAvailableIdleGearForAction(Ref ref, BaseAction baseAction) { final BuiltList watch = ref.watch(getAvailableIdleGearProvider); return watch.where((element) => baseAction.deviceCategory.contains(element.baseDeviceDefinition.deviceType)).toBuiltList(); } @Riverpod(keepAlive: true) -BuiltList getAvailableIdleGearForType(GetAvailableIdleGearForTypeRef ref, BuiltSet deviceTypes) { +BuiltList getAvailableIdleGearForType(Ref ref, BuiltSet deviceTypes) { final Iterable watch = ref.watch(getAvailableIdleGearProvider); return watch .where( @@ -135,7 +136,7 @@ BuiltList getAvailableIdleGearForType(GetAvailableIdleGearFo } @Riverpod(keepAlive: true) -BuiltList getAvailableGearForType(GetAvailableGearForTypeRef ref, BuiltSet deviceTypes) { +BuiltList getAvailableGearForType(Ref ref, BuiltSet deviceTypes) { final BuiltList watch = ref.watch(getAvailableGearProvider); return watch .where( @@ -145,7 +146,7 @@ BuiltList getAvailableGearForType(GetAvailableGearForTypeRef } @Riverpod(keepAlive: true) -BuiltList getKnownGearForType(GetKnownGearForTypeRef ref, BuiltSet deviceTypes) { +BuiltList getKnownGearForType(Ref ref, BuiltSet deviceTypes) { final BuiltMap watch = ref.watch(knownDevicesProvider); return watch.values .where( @@ -197,7 +198,7 @@ class GetAvailableGear extends _$GetAvailableGear { } @Riverpod(keepAlive: true) -bool isAllKnownGearConnected(IsAllKnownGearConnectedRef ref) { +bool isAllKnownGearConnected(Ref ref) { var knownGear = ref.watch(knownDevicesProvider); BuiltList connectedGear = ref.watch(getAvailableGearProvider); return knownGear.length == connectedGear.length; diff --git a/lib/Backend/firmware_update.dart b/lib/Backend/firmware_update.dart index 1e9ba514..b14fa03e 100644 --- a/lib/Backend/firmware_update.dart +++ b/lib/Backend/firmware_update.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'package:collection/collection.dart'; import 'package:crypto/crypto.dart'; import 'package:dio/dio.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:logging/logging.dart'; import 'package:package_info_plus/package_info_plus.dart'; @@ -38,7 +39,7 @@ class FWInfo with _$FWInfo { } @Riverpod(keepAlive: true) -Future?> getBaseFirmwareInfo(GetBaseFirmwareInfoRef ref, String url) async { +Future?> getBaseFirmwareInfo(Ref ref, String url) async { Dio dio = await initDio(); Future> valueFuture = dio.get(url, options: Options(responseType: ResponseType.json)) ..onError((error, stackTrace) { @@ -57,7 +58,7 @@ Future?> getBaseFirmwareInfo(GetBaseFirmwareInfoRef ref, String url } @Riverpod() -Future getFirmwareInfo(GetFirmwareInfoRef ref, String url, String hwVer) async { +Future getFirmwareInfo(Ref ref, String url, String hwVer) async { if (url.isEmpty || hwVer.isEmpty) { return null; } @@ -87,7 +88,7 @@ Future getFirmwareInfo(GetFirmwareInfoRef ref, String url, String hwVer } @Riverpod() -Future checkForFWUpdate(CheckForFWUpdateRef ref, BaseStatefulDevice baseStatefulDevice) async { +Future checkForFWUpdate(Ref ref, BaseStatefulDevice baseStatefulDevice) async { if (baseStatefulDevice.fwInfo.value != null) { return baseStatefulDevice.fwInfo.value; } @@ -106,7 +107,7 @@ Future checkForFWUpdate(CheckForFWUpdateRef ref, BaseStatefulDevice bas } @Riverpod() -Future hasOtaUpdate(HasOtaUpdateRef ref, BaseStatefulDevice baseStatefulDevice) async { +Future hasOtaUpdate(Ref ref, BaseStatefulDevice baseStatefulDevice) async { FWInfo? fwInfo = await ref.read(checkForFWUpdateProvider(baseStatefulDevice).future); Version fwVersion = baseStatefulDevice.fwVersion.value; diff --git a/lib/Backend/move_lists.dart b/lib/Backend/move_lists.dart index fa3bf5b4..2e276839 100644 --- a/lib/Backend/move_lists.dart +++ b/lib/Backend/move_lists.dart @@ -214,7 +214,7 @@ Future runAction(BaseAction action, BaseStatefulDevice device) async { } else if (action is MoveList) { sequencesLogger.info("Starting MoveList ${action.name}."); //plausible.event(name: "Run Sequence", props: {"Sequence Repeat": action.repeat.toInt().toString(), "Sequence Device Type": device.baseDeviceDefinition.deviceType.name, "Sequence Moves": action.moves.length.toString()}); - if (action.moves.isNotEmpty && action.moves.length <= 5 && (device.baseDeviceDefinition.deviceType != DeviceType.ears || device.isTailCoNTROL.value == tailControlStatus.tailControl)) { + if (action.moves.isNotEmpty && action.moves.length <= 5 && (device.baseDeviceDefinition.deviceType != DeviceType.ears || device.isTailCoNTROL.value == TailControlStatus.tailControl)) { int preset = 1; //TODO: store String cmd = "USERMOVE U${preset}P${action.moves.length}N${action.repeat.toInt()}"; String a = ''; // servo 1 position @@ -283,14 +283,14 @@ List generateMoveCommand(Move move, BaseStatefulDevice device, List commands = []; if (move.moveType == MoveType.home) { //TODO: Remove for TAILCoNTROL update - if (device.baseDeviceDefinition.deviceType == DeviceType.ears && device.isTailCoNTROL.value != tailControlStatus.tailControl) { + if (device.baseDeviceDefinition.deviceType == DeviceType.ears && device.isTailCoNTROL.value != TailControlStatus.tailControl) { commands.add(BluetoothMessage(message: "EARHOME", device: device, priority: priority, responseMSG: noResponseMsg ? null : "EARHOME END", type: type, timestamp: DateTime.now())); } else { commands.add(BluetoothMessage(message: "TAILHM", device: device, priority: priority, responseMSG: noResponseMsg ? null : "END TAILHM", type: type, timestamp: DateTime.now())); } } else if (move.moveType == MoveType.move) { //TODO: Remove for TAILCoNTROL update - if (device.baseDeviceDefinition.deviceType == DeviceType.ears && device.isTailCoNTROL.value != tailControlStatus.tailControl) { + if (device.baseDeviceDefinition.deviceType == DeviceType.ears && device.isTailCoNTROL.value != TailControlStatus.tailControl) { commands ..add( BluetoothMessage( diff --git a/lib/Backend/sensors.dart b/lib/Backend/sensors.dart index eb8f8f8a..d4f109a8 100644 --- a/lib/Backend/sensors.dart +++ b/lib/Backend/sensors.dart @@ -221,7 +221,7 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable p0.isTailCoNTROL.value == tailControlStatus.legacy, + (p0) => p0.isTailCoNTROL.value == TailControlStatus.legacy, ) .isNotEmpty; // add a glowtip action if it exists @@ -292,9 +292,9 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable>? _contextStreamSubscription; final _watch = WatchConnectivity(); @Riverpod(keepAlive: true) -Future initWear(InitWearRef ref) async { +Future initWear(Ref ref) async { await Future.delayed(const Duration(seconds: 5)); try { // Get the state of device connectivity @@ -34,7 +35,7 @@ Future initWear(InitWearRef ref) async { (event) => _wearLogger.info("Watch Context: $event"), ); - ref.read(updateWearActionsProvider); + //ref.read(updateWearActionsProvider); } catch (e, s) { _wearLogger.severe("exception setting up Wear $e", e, s); } @@ -65,7 +66,7 @@ Future> applicationContext() { } @Riverpod() -Future updateWearActions(UpdateWearActionsRef ref) async { +Future updateWearActions(Ref ref) async { if (await isWear()) { return; } diff --git a/lib/Frontend/Widgets/manage_gear.dart b/lib/Frontend/Widgets/manage_gear.dart index 5577fbef..25f92f65 100644 --- a/lib/Frontend/Widgets/manage_gear.dart +++ b/lib/Frontend/Widgets/manage_gear.dart @@ -409,7 +409,6 @@ class _ManageGearDebugState extends State { Text("UNSUPPORTED: ${widget.device.baseDeviceDefinition.unsupported}"), Text("MIN FIRMWARE: ${widget.device.baseDeviceDefinition.minVersion}"), Text("NVS Config: ${widget.device.gearConfigInfo.value}"), - Text("UART Service: ${widget.device.bluetoothUartService.value}"), ], ), ), @@ -584,7 +583,7 @@ class _ManageGearDebugState extends State { ), ListTile( title: const Text("isTailCoNTROL"), - trailing: DropdownMenu( + trailing: DropdownMenu( initialSelection: widget.device.isTailCoNTROL.value, onSelected: (value) { if (value != null) { @@ -595,13 +594,31 @@ class _ManageGearDebugState extends State { ); } }, - dropdownMenuEntries: tailControlStatus.values + dropdownMenuEntries: TailControlStatus.values .map( (e) => DropdownMenuEntry(value: e, label: e.name), ) .toList(), ), ), + ListTile( + title: const Text("bluetoothUartService"), + trailing: DropdownMenu( + initialSelection: widget.device.bluetoothUartService.value, + onSelected: (value) { + setState( + () { + widget.device.bluetoothUartService.value = value; + }, + ); + }, + dropdownMenuEntries: uartServices + .map( + (e) => DropdownMenuEntry(value: e, label: e.label), + ) + .toList(), + ), + ), ListTile( title: const Text("RSSI Level"), subtitle: Slider( diff --git a/lib/Frontend/Widgets/tail_blog.dart b/lib/Frontend/Widgets/tail_blog.dart index 61dd03d6..eb38f7af 100644 --- a/lib/Frontend/Widgets/tail_blog.dart +++ b/lib/Frontend/Widgets/tail_blog.dart @@ -245,7 +245,7 @@ class _TailBlogImageState extends ConsumerState { } @Riverpod(keepAlive: true) -Future getBlogImage(GetBlogImageRef ref, String url) async { +Future getBlogImage(Ref ref, String url) async { if (!await tailBlogConnectivityCheck()) { return Container(); } diff --git a/lib/Frontend/pages/action_selector.dart b/lib/Frontend/pages/action_selector.dart index 9fa22c9d..69d064d7 100644 --- a/lib/Frontend/pages/action_selector.dart +++ b/lib/Frontend/pages/action_selector.dart @@ -125,7 +125,7 @@ class _ActionSelectorState extends ConsumerState { tileMode: TileMode.clamp, ), ), - child: ButtonBar( + child: OverflowBar( alignment: MainAxisAlignment.center, children: [ FilledButton( diff --git a/lib/Frontend/pages/actions.dart b/lib/Frontend/pages/actions.dart index 5e13b8e6..00bc4c41 100644 --- a/lib/Frontend/pages/actions.dart +++ b/lib/Frontend/pages/actions.dart @@ -59,7 +59,7 @@ class _ActionPageBuilderState extends ConsumerState { child: ref .watch(getAvailableGearForTypeProvider(BuiltSet([DeviceType.ears]))) .where( - (p0) => p0.isTailCoNTROL.value == tailControlStatus.legacy, + (p0) => p0.isTailCoNTROL.value == TailControlStatus.legacy, ) .isNotEmpty ? const EarSpeedWidget() @@ -197,13 +197,13 @@ class _ActionCardState extends ConsumerState { (baseStatefulDevice) { //TODO: remove after tailcontrol migration period if (widget.action.deviceCategory.contains(DeviceType.ears) && baseStatefulDevice.baseDeviceDefinition.deviceType == DeviceType.ears) { - if (baseStatefulDevice.isTailCoNTROL.value == tailControlStatus.tailControl) { + if (baseStatefulDevice.isTailCoNTROL.value == TailControlStatus.tailControl) { // skip legacy moves if (widget.action is EarsMoveList) { return false; } // skip unified moves for legacy firmware ears - } else if (baseStatefulDevice.isTailCoNTROL.value == tailControlStatus.legacy) { + } else if (baseStatefulDevice.isTailCoNTROL.value == TailControlStatus.legacy) { if (widget.action is CommandAction) { return false; } diff --git a/lib/Frontend/pages/home.dart b/lib/Frontend/pages/home.dart index 17f303c9..f39dad60 100644 --- a/lib/Frontend/pages/home.dart +++ b/lib/Frontend/pages/home.dart @@ -85,7 +85,7 @@ class _HomeState extends ConsumerState { title: Text(homeWelcomeMessageTitle()), subtitle: Text(homeWelcomeMessage()), ), - ButtonBar( + OverflowBar( children: [ TextButton( onPressed: () async { diff --git a/lib/Frontend/pages/intro.dart b/lib/Frontend/pages/intro.dart index 5333904c..c82151f5 100644 --- a/lib/Frontend/pages/intro.dart +++ b/lib/Frontend/pages/intro.dart @@ -110,7 +110,7 @@ class OnBoardingPageState extends ConsumerState { asset: Assets.tailcostickers.tailCoStickersFile144834359, width: MediaQuery.of(context).size.width, ), - footer: ButtonBar( + footer: OverflowBar( alignment: MainAxisAlignment.center, children: [ ElevatedButton( @@ -154,7 +154,7 @@ class OnBoardingPageState extends ConsumerState { asset: Assets.tailcostickers.tailCoStickersFile144834357, width: MediaQuery.of(context).size.width, ), - footer: ButtonBar( + footer: OverflowBar( alignment: MainAxisAlignment.center, children: [ FilledButton( diff --git a/lib/Frontend/pages/triggers.dart b/lib/Frontend/pages/triggers.dart index 891bc2e1..ba6fedec 100644 --- a/lib/Frontend/pages/triggers.dart +++ b/lib/Frontend/pages/triggers.dart @@ -342,7 +342,7 @@ class _TriggerEditState extends ConsumerState { .map( (e) => ref.read(getActionFromUUIDProvider(e)), ) - .whereNotNull() + .nonNulls .toList(), ), ), @@ -370,7 +370,7 @@ class _TriggerEditState extends ConsumerState { ), ), ), - ButtonBar( + OverflowBar( children: [ TextButton( onPressed: () async {