improved ui and code warnings
This commit is contained in:
parent
f635a4bae3
commit
dc20c8c171
|
@ -16,15 +16,15 @@ class BluetoothObject {
|
||||||
|
|
||||||
String id = "";
|
String id = "";
|
||||||
String _primaryThumbprint = "";
|
String _primaryThumbprint = "";
|
||||||
String _secondaryThumbprint = "";
|
final String _secondaryThumbprint = "";
|
||||||
|
|
||||||
late BluetoothConnection? _connection;
|
late BluetoothConnection? _connection;
|
||||||
late Stream<Uint8List> _connectionStream;
|
late Stream<Uint8List> _connectionStream;
|
||||||
late StreamSubscription<Uint8List> _connectionStreamSubscription;
|
late StreamSubscription<Uint8List> _connectionStreamSubscription;
|
||||||
|
|
||||||
CloudServiceAPI _cloudServiceAPI = CloudServiceAPI();
|
final CloudServiceAPI _cloudServiceAPI = CloudServiceAPI();
|
||||||
|
|
||||||
late Uint8List _messageBufferBits;
|
//late Uint8List _messageBufferBits;
|
||||||
late String _messageBufferChars = "";
|
late String _messageBufferChars = "";
|
||||||
|
|
||||||
bool _isDisconnecting = false;
|
bool _isDisconnecting = false;
|
||||||
|
@ -222,8 +222,6 @@ class BluetoothObject {
|
||||||
Future<void> sendData(String output) async {
|
Future<void> sendData(String output) async {
|
||||||
if (_connection == null) return;
|
if (_connection == null) return;
|
||||||
bool nameAvailable = await _cloudServiceAPI.checkNameAvailability(output);
|
bool nameAvailable = await _cloudServiceAPI.checkNameAvailability(output);
|
||||||
// String output = "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";// !§%&()=?#!?";
|
|
||||||
// String output = "myDevice123";// !§%&()=?#!?";
|
|
||||||
if (!nameAvailable) return;
|
if (!nameAvailable) return;
|
||||||
id = output;
|
id = output;
|
||||||
_connection!.output.add(Uint8List.fromList(const AsciiEncoder().convert("$output \r\n")));
|
_connection!.output.add(Uint8List.fromList(const AsciiEncoder().convert("$output \r\n")));
|
||||||
|
|
|
@ -14,8 +14,7 @@ class BluetoothDeviceSettings extends StatefulWidget {
|
||||||
|
|
||||||
class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
|
class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
|
||||||
late BluetoothObject _bluetoothObject;
|
late BluetoothObject _bluetoothObject;
|
||||||
|
String _textInput = ""; // 0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
String _messageBuffer = "";
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -23,9 +22,6 @@ class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
|
||||||
_bluetoothObject = widget.bluetoothObject;
|
_bluetoothObject = widget.bluetoothObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _textInput = "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
||||||
String _textOuput = "";
|
|
||||||
|
|
||||||
ButtonStyle buttonStyle = ElevatedButton.styleFrom(
|
ButtonStyle buttonStyle = ElevatedButton.styleFrom(
|
||||||
foregroundColor: Colors.black,
|
foregroundColor: Colors.black,
|
||||||
backgroundColor: const Color(0xFFFDE100), // Text Color (Foreground color)
|
backgroundColor: const Color(0xFFFDE100), // Text Color (Foreground color)
|
||||||
|
@ -59,7 +55,7 @@ class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 0.0),
|
||||||
child: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
|
child: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
|
||||||
// const EdgeInsets defaultContentPadding = EdgeInsets.symmetric(horizontal: 16.0);
|
// const EdgeInsets defaultContentPadding = EdgeInsets.symmetric(horizontal: 16.0);
|
||||||
Expanded(
|
Expanded(
|
||||||
|
@ -85,6 +81,12 @@ class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
|
||||||
))
|
))
|
||||||
])),
|
])),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 0.0),
|
||||||
|
child:
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child:
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
_bluetoothObject.sendData(_textInput);
|
_bluetoothObject.sendData(_textInput);
|
||||||
|
@ -92,18 +94,10 @@ class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
|
||||||
style: buttonStyle,
|
style: buttonStyle,
|
||||||
child: const Text("Send Data"),
|
child: const Text("Send Data"),
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
)
|
||||||
onPressed: () async {
|
|
||||||
setState(() {
|
|
||||||
_textOuput = "";
|
|
||||||
});
|
|
||||||
},
|
|
||||||
style: buttonStyle,
|
|
||||||
child: const Text("Clear Output"),
|
|
||||||
),
|
),
|
||||||
Text(_textOuput),
|
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
|
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||||
child: TextField(
|
child: TextField(
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
|
|
|
@ -50,7 +50,7 @@ class _BluetoothScreen extends State<BluetoothScreen> {
|
||||||
_activeObject = null;
|
_activeObject = null;
|
||||||
_streamSubscription = null;
|
_streamSubscription = null;
|
||||||
if (widget.start) {
|
if (widget.start) {
|
||||||
_startDiscovery();
|
_initAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +63,13 @@ class _BluetoothScreen extends State<BluetoothScreen> {
|
||||||
debugPrint("called dispose");
|
debugPrint("called dispose");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _initAsync() async {
|
||||||
|
await _enablePermissions();
|
||||||
|
await _enableBluetooth();
|
||||||
|
await _startDiscovery();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _enablePermissions() async {
|
Future<void> _enablePermissions() async {
|
||||||
debugPrint("Test");
|
|
||||||
PermissionStatus bluetoothScan = await Permission.bluetoothScan.request();
|
PermissionStatus bluetoothScan = await Permission.bluetoothScan.request();
|
||||||
PermissionStatus bluetoothConnect = await Permission.bluetoothConnect.request();
|
PermissionStatus bluetoothConnect = await Permission.bluetoothConnect.request();
|
||||||
bool granted = bluetoothScan.isGranted && bluetoothConnect.isGranted;
|
bool granted = bluetoothScan.isGranted && bluetoothConnect.isGranted;
|
||||||
|
@ -74,7 +79,14 @@ class _BluetoothScreen extends State<BluetoothScreen> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _enableBluetooth() async {
|
Future<void> _enableBluetooth() async {
|
||||||
if (!_enabledPermissions) {
|
if (_enabledBluetooth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BluetoothState state = await FlutterBluetoothSerial.instance.state;
|
||||||
|
if (state == BluetoothState.STATE_ON) {
|
||||||
|
setState(() {
|
||||||
|
_enabledBluetooth = true;
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool? enabled = await FlutterBluetoothSerial.instance.requestEnable();
|
bool? enabled = await FlutterBluetoothSerial.instance.requestEnable();
|
||||||
|
@ -85,7 +97,8 @@ class _BluetoothScreen extends State<BluetoothScreen> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _startDiscovery() async {
|
Future<void> _startDiscovery() async {
|
||||||
if (!_enabledPermissions) {
|
debugPrint("enabled: $_enabledPermissions");
|
||||||
|
if (!_enabledPermissions && !_enabledBluetooth) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() => _isDiscovering = true);
|
setState(() => _isDiscovering = true);
|
||||||
|
@ -137,9 +150,6 @@ class _BluetoothScreen extends State<BluetoothScreen> {
|
||||||
_activeObject!.isConnected ? await bluetoothObject.disconnectDevice() : await bluetoothObject.connectDevice();
|
_activeObject!.isConnected ? await bluetoothObject.disconnectDevice() : await bluetoothObject.connectDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
//stty -F /dev/service 19200 parenb -parodd -cstopb cs8
|
|
||||||
//cat /dev/service | xargs -n 1 /home/script/automaticcloud.sh
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
|
Loading…
Reference in New Issue