Skip to content

Instantly share code, notes, and snippets.

@sbis04
Created March 4, 2019 17:58
Show Gist options
  • Save sbis04/97f432e39a9f9cc1f06be5fe4cfd873d to your computer and use it in GitHub Desktop.
Save sbis04/97f432e39a9f9cc1f06be5fe4cfd873d to your computer and use it in GitHub Desktop.
Implementing _connect, _disconnect and show methods
...
// Method to connect to bluetooth
void _connect() {
if (_device == null) {
show('No device selected');
} else {
bluetooth.isConnected.then((isConnected) {
if (!isConnected) {
bluetooth
.connect(_device)
.timeout(Duration(seconds: 10))
.catchError((error) {
setState(() => _pressed = false);
});
setState(() => _pressed = true);
}
});
}
}
// Method to disconnect bluetooth
void _disconnect() {
bluetooth.disconnect();
setState(() => _pressed = true);
}
// Method to show a Snackbar,
// taking message as the text
Future show(
String message, {
Duration duration: const Duration(seconds: 3),
}) async {
await new Future.delayed(new Duration(milliseconds: 100));
_scaffoldKey.currentState.showSnackBar(
new SnackBar(
content: new Text(
message,
),
duration: duration,
),
);
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment