Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. // Método que conecta o bluetooth
  2. void _connect() {
  3. if (_device == null) {
  4. show(‘No device selected’);
  5. } else {
  6. bluetooth.isConnected.then((isConnected) {
  7. if (!isConnected) {
  8. bluetooth
  9. .connect(_device)
  10. .timeout(Duration(seconds: 10))
  11. .catchError((error) {
  12. setState(() => _pressed = false);
  13. });
  14. setState(() => _pressed = true);
  15. }
  16. });
  17. }
  18. }
  19.  
  20. // Método que desconecta o bluetooth
  21. void _disconnect() {
  22. bluetooth.disconnect();
  23. setState(() => _pressed = true);
  24. }
  25.  
  26. // Método que exibe a Snackbar com a mensagem
  27. Future show(
  28. String message, {
  29. Duration duration: const Duration(seconds: 3),
  30. }) async {
  31. await new Future.delayed(new Duration(milliseconds: 100));
  32. _scaffoldKey.currentState.showSnackBar(
  33. new SnackBar(
  34. content: new Text(
  35. message,
  36. ),
  37. duration: duration,
  38. ),
  39. );
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement