Skip to content

Commit

Permalink
[Example] add error handling to descriptor read & write
Browse files Browse the repository at this point in the history
  • Loading branch information
chipweinberger committed Jul 24, 2023
1 parent 8b2444b commit ce2aa73
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,22 @@ class DeviceScreen extends StatelessWidget {
.map(
(d) => DescriptorTile(
descriptor: d,
onReadPressed: () => d.read(),
onWritePressed: () => d.write(_getRandomBytes()),
onReadPressed: () async {
try {
await d.read();
} catch (e) {
final snackBar = SnackBar(content: Text(prettyException("Read Error:", e)));
snackBarKeyC.currentState?.showSnackBar(snackBar);
}
},
onWritePressed: () async {
try {
await d.write(_getRandomBytes());
} catch (e) {
final snackBar = SnackBar(content: Text(prettyException("Write Error:", e)));
snackBarKeyC.currentState?.showSnackBar(snackBar);
}
},
),
)
.toList(),
Expand Down

0 comments on commit ce2aa73

Please sign in to comment.