From 90caa2402d0c289669a55d0f1fc9d1909b47b439 Mon Sep 17 00:00:00 2001 From: Turtlepaw <81275769+Turtlepaw@users.noreply.github.com> Date: Sun, 1 Sep 2024 00:05:19 -0400 Subject: [PATCH] feat: add refresh button and handle no connected devices Added a refresh button to trigger health data fetching and connection status check. Also handled the case when no devices are connected to the watch. --- android/gradle.properties | 2 +- lib/routes/settings.dart | 22 ++++++++++++++++++---- lib/utils/health.dart | 6 +++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index e07f978..a892124 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,4 +1,4 @@ -#org.gradle.jvmargs=-Xmx2048M +org.gradle.jvmargs=-Xmx2048M # org.gradle.jvmargs=-XX:MaxPermSize=512m android.enableJetifier=true android.useAndroidX=true \ No newline at end of file diff --git a/lib/routes/settings.dart b/lib/routes/settings.dart index bed9548..9d986b6 100644 --- a/lib/routes/settings.dart +++ b/lib/routes/settings.dart @@ -28,6 +28,7 @@ class _SettingsPageState extends State { bool _isHealthConnected = false; bool _isWatchLoading = false; bool _isSysHealthLoading = false; + bool _isRefreshing = false; late String username; late PocketBase pb; late HealthType? healthType; @@ -352,10 +353,23 @@ class _SettingsPageState extends State { const SizedBox( width: 5, ), - IconButton.outlined(onPressed: (){ - health.fetchHealthData(); - health.checkConnectionState(); - }, icon: Icon(Symbols.refresh_rounded, color: theme.colorScheme.onSurface,)) + IconButton.outlined(onPressed: () async { + setState(() { + _isRefreshing = true; + }); + await health.fetchHealthData(); + await health.checkConnectionState(); + setState(() { + _isRefreshing = false; + }); + }, icon: _isRefreshing ? const SizedBox( + width: 15, + height: 15, + child: CircularProgressIndicator( + strokeWidth: 2, + strokeCap: StrokeCap.round, + ), + ) : Icon(Symbols.refresh_rounded, color: theme.colorScheme.onSurface,)) ], ) ]), diff --git a/lib/utils/health.dart b/lib/utils/health.dart index f0c8242..bc09c28 100644 --- a/lib/utils/health.dart +++ b/lib/utils/health.dart @@ -66,7 +66,7 @@ class HealthManager with ChangeNotifier { } /// Attempts to fetch health data if all permissions are granted - void fetchHealthData({BuildContext? context}) async { + Future fetchHealthData({BuildContext? context}) async { final health = Health(); final type = await HealthTypeManager().getHealthType(); @@ -95,6 +95,10 @@ class HealthManager with ChangeNotifier { await flutterWearOsConnectivity.configureWearableAPI(); var devices = await flutterWearOsConnectivity.getConnectedDevices(); + if(devices.isEmpty){ + print("No connected devices"); + return; + } for (var device in devices) { await flutterWearOsConnectivity