improved ui and code warnings

This commit is contained in:
YamiDoesDev 2023-01-07 16:38:23 +01:00
parent f635a4bae3
commit dc20c8c171
3 changed files with 38 additions and 36 deletions

View File

@ -16,15 +16,15 @@ class BluetoothObject {
String id = "";
String _primaryThumbprint = "";
String _secondaryThumbprint = "";
final String _secondaryThumbprint = "";
late BluetoothConnection? _connection;
late Stream<Uint8List> _connectionStream;
late StreamSubscription<Uint8List> _connectionStreamSubscription;
CloudServiceAPI _cloudServiceAPI = CloudServiceAPI();
final CloudServiceAPI _cloudServiceAPI = CloudServiceAPI();
late Uint8List _messageBufferBits;
//late Uint8List _messageBufferBits;
late String _messageBufferChars = "";
bool _isDisconnecting = false;
@ -222,8 +222,6 @@ class BluetoothObject {
Future<void> sendData(String output) async {
if (_connection == null) return;
bool nameAvailable = await _cloudServiceAPI.checkNameAvailability(output);
// String output = "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";// !§%&()=?#!?";
// String output = "myDevice123";// !§%&()=?#!?";
if (!nameAvailable) return;
id = output;
_connection!.output.add(Uint8List.fromList(const AsciiEncoder().convert("$output \r\n")));

View File

@ -14,8 +14,7 @@ class BluetoothDeviceSettings extends StatefulWidget {
class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
late BluetoothObject _bluetoothObject;
String _messageBuffer = "";
String _textInput = ""; // 0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
@override
void initState() {
@ -23,9 +22,6 @@ class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
_bluetoothObject = widget.bluetoothObject;
}
String _textInput = "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String _textOuput = "";
ButtonStyle buttonStyle = ElevatedButton.styleFrom(
foregroundColor: Colors.black,
backgroundColor: const Color(0xFFFDE100), // Text Color (Foreground color)
@ -59,7 +55,7 @@ class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
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(
@ -85,6 +81,12 @@ class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
))
])),
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);
@ -92,18 +94,10 @@ class BluetoothDeviceSettingsState extends State<BluetoothDeviceSettings> {
style: buttonStyle,
child: const Text("Send Data"),
),
ElevatedButton(
onPressed: () async {
setState(() {
_textOuput = "";
});
},
style: buttonStyle,
child: const Text("Clear Output"),
)
),
Text(_textOuput),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
child: TextField(
decoration: const InputDecoration(
border: OutlineInputBorder(),

View File

@ -50,7 +50,7 @@ class _BluetoothScreen extends State<BluetoothScreen> {
_activeObject = null;
_streamSubscription = null;
if (widget.start) {
_startDiscovery();
_initAsync();
}
}
@ -63,8 +63,13 @@ class _BluetoothScreen extends State<BluetoothScreen> {
debugPrint("called dispose");
}
Future<void> _initAsync() async {
await _enablePermissions();
await _enableBluetooth();
await _startDiscovery();
}
Future<void> _enablePermissions() async {
debugPrint("Test");
PermissionStatus bluetoothScan = await Permission.bluetoothScan.request();
PermissionStatus bluetoothConnect = await Permission.bluetoothConnect.request();
bool granted = bluetoothScan.isGranted && bluetoothConnect.isGranted;
@ -74,7 +79,14 @@ class _BluetoothScreen extends State<BluetoothScreen> {
}
Future<void> _enableBluetooth() async {
if (!_enabledPermissions) {
if (_enabledBluetooth) {
return;
}
BluetoothState state = await FlutterBluetoothSerial.instance.state;
if (state == BluetoothState.STATE_ON) {
setState(() {
_enabledBluetooth = true;
});
return;
}
bool? enabled = await FlutterBluetoothSerial.instance.requestEnable();
@ -85,7 +97,8 @@ class _BluetoothScreen extends State<BluetoothScreen> {
}
Future<void> _startDiscovery() async {
if (!_enabledPermissions) {
debugPrint("enabled: $_enabledPermissions");
if (!_enabledPermissions && !_enabledBluetooth) {
return;
}
setState(() => _isDiscovering = true);
@ -137,9 +150,6 @@ class _BluetoothScreen extends State<BluetoothScreen> {
_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
Widget build(BuildContext context) {
return Scaffold(