Skip to content

Commit

Permalink
feat(trait_device_screen): show toast with error message if any error…
Browse files Browse the repository at this point in the history
… occurs
  • Loading branch information
ses110 committed Dec 10, 2021
1 parent 5ccffa2 commit 0cebb62
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/providers/power_trait_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class PowerTraitProvider extends ChangeNotifier {
} catch (error) {
setErrorMessage = error.toString();
setErrorState = true;
Future.delayed(Duration(seconds: 1)).then((_) => setErrorState = false);
await Future.delayed(Duration(seconds: 1))
.then((_) => setErrorState = false);
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions lib/traits/trait_based_device_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ class PowerTraitWidget extends StatelessWidget {
if (powerDeviceNotifier.isBusy) {
return CircularProgressIndicator();
} else if (powerDeviceNotifier.isInErrorState) {
print(
"PowerDeviceTrait Error: ${powerDeviceNotifier.getErrorMessage}");
_showToast(context, powerDeviceNotifier.getErrorMessage);
return Icon(Icons.error);
} else {
return CupertinoSwitch(
Expand All @@ -143,6 +142,13 @@ class PowerTraitWidget extends StatelessWidget {
}),
);
}

void _showToast(BuildContext context, String message) {
WidgetsBinding.instance!
.addPostFrameCallback((_) => ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message)),
));
}
}

class UnknownTraitWidget extends StatelessWidget {
Expand Down

0 comments on commit 0cebb62

Please sign in to comment.