Created
March 4, 2019 17:58
-
-
Save sbis04/97f432e39a9f9cc1f06be5fe4cfd873d to your computer and use it in GitHub Desktop.
Implementing _connect, _disconnect and show methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// 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