Skip to content

Commit

Permalink
feat: add refresh button and handle no connected devices
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Turtlepaw committed Sep 1, 2024
1 parent 0a71fa9 commit 90caa24
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#org.gradle.jvmargs=-Xmx2048M
org.gradle.jvmargs=-Xmx2048M
# org.gradle.jvmargs=-XX:MaxPermSize=512m
android.enableJetifier=true
android.useAndroidX=true
22 changes: 18 additions & 4 deletions lib/routes/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class _SettingsPageState extends State<SettingsPage> {
bool _isHealthConnected = false;
bool _isWatchLoading = false;
bool _isSysHealthLoading = false;
bool _isRefreshing = false;
late String username;
late PocketBase pb;
late HealthType? healthType;
Expand Down Expand Up @@ -352,10 +353,23 @@ class _SettingsPageState extends State<SettingsPage> {
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,))
],
)
]),
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/health.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class HealthManager with ChangeNotifier {
}

/// Attempts to fetch health data if all permissions are granted
void fetchHealthData({BuildContext? context}) async {
Future<void> fetchHealthData({BuildContext? context}) async {
final health = Health();
final type = await HealthTypeManager().getHealthType();

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 90caa24

Please sign in to comment.