semesterprojekt-bluetooth-p.../lib/screens/bluetooth_device_settings.dart

116 lines
4.1 KiB
Dart

import 'package:flutter/material.dart';
import '../objects/bluetooth_object.dart';
import '../widgets/single_section.dart';
class BluetoothDeviceSettings extends StatefulWidget {
final BluetoothObject bluetoothObject;
const BluetoothDeviceSettings({super.key, required this.bluetoothObject});
@override
State<StatefulWidget> createState() => BluetoothDeviceSettingsState();
}
class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
late BluetoothObject _bluetoothObject;
String _textInput = ""; // 0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
@override
void initState() {
super.initState();
_bluetoothObject = widget.bluetoothObject;
}
ButtonStyle buttonStyle = ElevatedButton.styleFrom(
foregroundColor: Colors.black,
backgroundColor: const Color(0xFFFDE100), // Text Color (Foreground color)
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Device Settings"),
),
body: Center(
child: ListView(children: [
Column(children: <Widget>[
SingleSection(
title: "Device Information",
children: [
ListTile(
title: const Text("Device Name"),
subtitle: Text(_bluetoothObject.name),
),
ListTile(
title: const Text("Device Adress"),
subtitle: Text(_bluetoothObject.address),
),
ListTile(
title: const Text("Device Connection State"),
subtitle:
Text(_bluetoothObject.isConnected ? "ConnectionState.DISCONECTED" : "ConnectionState.CONNECED"),
),
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 0.0),
child: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
// const EdgeInsets defaultContentPadding = EdgeInsets.symmetric(horizontal: 16.0);
Expanded(
child: ElevatedButton(
onPressed: () async {
if (!_bluetoothObject.isConnected) {
await _bluetoothObject.connectDevice();
}
},
style: buttonStyle,
child: const Text("Connect"),
)),
const SizedBox(width: 16.0),
Expanded(
child: ElevatedButton(
onPressed: () async {
if (_bluetoothObject.isConnected) {
await _bluetoothObject.disconnectDevice();
}
},
style: buttonStyle,
child: const Text("Disconnect"),
))
])),
const Divider(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 0.0),
child:
SizedBox(
width: double.infinity,
child:
ElevatedButton(
onPressed: () async {
_bluetoothObject.sendData(_textInput);
},
style: buttonStyle,
child: const Text("Send Data"),
),
)
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),
hintText: 'Enter the device name',
),
onChanged: (String newValue) {
_textInput = newValue;
},
),
),
]),
]),
));
}
}