Skip to content

Instantly share code, notes, and snippets.

@sbis04
Last active March 4, 2019 17:49
Show Gist options
  • Save sbis04/0abd2335e98225055f6a890073e58e71 to your computer and use it in GitHub Desktop.
Save sbis04/0abd2335e98225055f6a890073e58e71 to your computer and use it in GitHub Desktop.
UI Part
...
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text("Flutter Bluetooth"),
backgroundColor: Colors.deepPurple,
),
body: Container(
// Defining a Column containing FOUR main Widgets wrapped with some padding:
// 1. Text
// 2. Row
// 3. Card
// 4. Text (wrapped with "Expanded" and "Padding")
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text(
"PAIRED DEVICES",
style: TextStyle(fontSize: 24, color: Colors.blue),
textAlign: TextAlign.center,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
// Defining a Row containing THREE main Widgets:
// 1. Text
// 2. DropdownButton
// 3. RaisedButton
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Device:',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
DropdownButton(
// To be implemented : _getDeviceItems()
items: _getDeviceItems(),
onChanged: (value) => setState(() => _device = value),
value: _device,
),
RaisedButton(
onPressed:
// To be implemented : _disconnect and _connect
_pressed ? null : _connected ? _disconnect : _connect,
child: Text(_connected ? 'Disconnect' : 'Connect'),
),
],
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Card(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(8.0),
// Defining a Row containing THREE main Widgets:
// 1. Text (wrapped with "Expanded")
// 2. FlatButton
// 3. FlatButton
child: Row(
children: <Widget>[
Expanded(
child: Text(
"DEVICE 1",
style: TextStyle(
fontSize: 20,
color: Colors.green,
),
),
),
FlatButton(
onPressed:
// To be implemented : _sendOnMessageToBluetooth()
_connected ? _sendOnMessageToBluetooth : null,
child: Text("ON"),
),
FlatButton(
onPressed:
// To be implemented : _sendOffMessageToBluetooth()
_connected ? _sendOffMessageToBluetooth : null,
child: Text("OFF"),
),
],
),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(20),
child: Center(
child: Text(
"NOTE: If you cannot find the device in the list, "
"please turn on bluetooth and pair the device by "
"going to the bluetooth settings",
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.red),
),
),
),
)
],
),
),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment