From 1259bb5472fbbc845073df6a8c67208841eb6bb1 Mon Sep 17 00:00:00 2001 From: Codel1417 <13484789+Codel1417@users.noreply.github.com> Date: Wed, 22 May 2024 11:42:21 -0400 Subject: [PATCH] re-organize some known gear helpers and handle unknown battery % --- lib/Frontend/Widgets/known_gear.dart | 46 ++++++++++++++++++++++++++++ lib/Frontend/pages/shell.dart | 42 ------------------------- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/lib/Frontend/Widgets/known_gear.dart b/lib/Frontend/Widgets/known_gear.dart index f0fc3cf0..29571840 100644 --- a/lib/Frontend/Widgets/known_gear.dart +++ b/lib/Frontend/Widgets/known_gear.dart @@ -1,6 +1,7 @@ import 'package:animate_do/animate_do.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:sentry_hive/sentry_hive.dart'; import 'package:tail_app/Backend/Definitions/Device/device_definition.dart'; import 'package:tail_app/Frontend/Widgets/scan_for_new_device.dart'; @@ -225,4 +226,49 @@ class _KnownGearCardState extends ConsumerState { ), ); } + + Widget getSignal(int rssi) { + if (rssi < -2) { + return const Icon(Icons.signal_cellular_alt); + } else if (rssi <= -45) { + return const Icon(Icons.signal_cellular_alt_2_bar); + } else if (rssi < -65) { + return const Icon(Icons.signal_cellular_alt_1_bar); + } else { + return const Icon(Icons.signal_cellular_connected_no_internet_0_bar); + } + } + + Widget getBattery(double level) { + if (SentryHive.box(settings).get(showAccurateBattery, defaultValue: showAccurateBatteryDefault)) { + if (level < 0) { + // battery level is unknown + return const Text('?%'); + } + return Text('${level.toInt()}%'); + } + if (level < 0) { + return const Icon(Icons.battery_unknown); + } + if (level < 12.5) { + return Flash(infinite: true, child: const Icon(Icons.battery_0_bar)); + } else if (level < 25) { + return Flash( + infinite: true, + child: const Icon(Icons.battery_1_bar), + ); + } else if (level < 37.5) { + return const Icon(Icons.battery_2_bar); + } else if (level < 50) { + return const Icon(Icons.battery_3_bar); + } else if (level < 62.5) { + return const Icon(Icons.battery_4_bar); + } else if (level < 75) { + return const Icon(Icons.battery_5_bar); + } else if (level < 87.5) { + return const Icon(Icons.battery_6_bar); + } else { + return const Icon(Icons.battery_full); + } + } } diff --git a/lib/Frontend/pages/shell.dart b/lib/Frontend/pages/shell.dart index b65d57c0..326e5a06 100644 --- a/lib/Frontend/pages/shell.dart +++ b/lib/Frontend/pages/shell.dart @@ -1,4 +1,3 @@ -import 'package:animate_do/animate_do.dart'; import 'package:fl_chart/fl_chart.dart'; import 'package:flex_color_picker/flex_color_picker.dart'; import 'package:flutter/material.dart'; @@ -52,47 +51,6 @@ class NavigationDrawerExample extends ConsumerStatefulWidget { ConsumerState createState() => _NavigationDrawerExampleState(); } -Widget getSignal(int rssi) { - if (rssi < -2) { - return const Icon(Icons.signal_cellular_alt); - } else if (rssi <= -45) { - return const Icon(Icons.signal_cellular_alt_2_bar); - } else if (rssi < -65) { - return const Icon(Icons.signal_cellular_alt_1_bar); - } else { - return const Icon(Icons.signal_cellular_connected_no_internet_0_bar); - } -} - -Widget getBattery(double level) { - if (SentryHive.box(settings).get(showAccurateBattery, defaultValue: showAccurateBatteryDefault)) { - return Text('${level.toInt()}%'); - } - if (level < 0) { - return const Icon(Icons.battery_unknown); - } - if (level < 12.5) { - return Flash(infinite: true, child: const Icon(Icons.battery_0_bar)); - } else if (level < 25) { - return Flash( - infinite: true, - child: const Icon(Icons.battery_1_bar), - ); - } else if (level < 37.5) { - return const Icon(Icons.battery_2_bar); - } else if (level < 50) { - return const Icon(Icons.battery_3_bar); - } else if (level < 62.5) { - return const Icon(Icons.battery_4_bar); - } else if (level < 75) { - return const Icon(Icons.battery_5_bar); - } else if (level < 87.5) { - return const Icon(Icons.battery_6_bar); - } else { - return const Icon(Icons.battery_full); - } -} - class _NavigationDrawerExampleState extends ConsumerState { int screenIndex = 0; bool showAppBar = true;