device name quirk fixed
This commit is contained in:
@@ -126,6 +126,7 @@ class _DevicesMenuState extends State<DevicesMenu> {
|
||||
deviceId: device['id'],
|
||||
peripheralNum: portNums[0],
|
||||
deviceName: device['name'],
|
||||
isSinglePort: true,
|
||||
),
|
||||
),
|
||||
).then((_) { getDevices(); });
|
||||
|
||||
@@ -11,11 +11,12 @@ import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:socket_io_client/socket_io_client.dart' as IO;
|
||||
|
||||
class PeripheralScreen extends StatefulWidget {
|
||||
const PeripheralScreen({super.key, required this.peripheralId, required this.deviceId, required this.peripheralNum, required this.deviceName});
|
||||
const PeripheralScreen({super.key, required this.peripheralId, required this.deviceId, required this.peripheralNum, required this.deviceName, this.isSinglePort = false});
|
||||
final int peripheralId;
|
||||
final int peripheralNum;
|
||||
final int deviceId;
|
||||
final String deviceName;
|
||||
final bool isSinglePort;
|
||||
@override
|
||||
State<PeripheralScreen> createState() => _PeripheralScreenState();
|
||||
}
|
||||
@@ -23,6 +24,7 @@ class PeripheralScreen extends StatefulWidget {
|
||||
class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
IO.Socket? socket;
|
||||
String imagePath = "";
|
||||
late String _deviceName;
|
||||
String peripheralName = "...";
|
||||
bool loaded = false;
|
||||
bool calibrated = false;
|
||||
@@ -55,6 +57,7 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_deviceName = widget.deviceName;
|
||||
initAll();
|
||||
initSocket();
|
||||
}
|
||||
@@ -444,10 +447,13 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
builder: (BuildContext dialogContext) {
|
||||
return AlertDialog(
|
||||
title: Text(
|
||||
"Rename Peripheral",
|
||||
widget.isSinglePort ? "Rename Device" : "Rename Peripheral",
|
||||
style: GoogleFonts.aBeeZee(),
|
||||
),
|
||||
content: BlindMasterMainInput("New Peripheral Name", controller: _peripheralRenameController,),
|
||||
content: BlindMasterMainInput(
|
||||
widget.isSinglePort ? "New Device Name" : "New Peripheral Name",
|
||||
controller: _peripheralRenameController,
|
||||
),
|
||||
actions: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
@@ -458,14 +464,16 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
},
|
||||
child: const Text(
|
||||
"Cancel",
|
||||
style: TextStyle(
|
||||
color: Colors.red
|
||||
),
|
||||
style: TextStyle(color: Colors.red),
|
||||
)
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
updatePeriphName(_peripheralRenameController.text, widget.peripheralId);
|
||||
if (widget.isSinglePort) {
|
||||
updateDeviceName(_peripheralRenameController.text);
|
||||
} else {
|
||||
updatePeriphName(_peripheralRenameController.text, widget.peripheralId);
|
||||
}
|
||||
Navigator.of(dialogContext).pop();
|
||||
},
|
||||
child: const Text("Confirm")
|
||||
@@ -478,6 +486,27 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Future updateDeviceName(String name) async {
|
||||
try {
|
||||
if (name.isEmpty) throw Exception("New name cannot be empty!");
|
||||
final payload = {
|
||||
'deviceId': widget.deviceId,
|
||||
'newName': name,
|
||||
};
|
||||
final response = await securePost(payload, 'rename_device');
|
||||
if (response == null) throw Exception("Auth Error");
|
||||
if (response.statusCode != 204) {
|
||||
if (response.statusCode == 409) throw Exception("Choose a unique name!");
|
||||
throw Exception("Server Error");
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() => _deviceName = name);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future updatePeriphName(String name, int id) async {
|
||||
try {
|
||||
if (name.isEmpty) throw Exception("New name cannot be empty!");
|
||||
@@ -566,9 +595,10 @@ class _PeripheralScreenState extends State<PeripheralScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
"${widget.deviceName} - $peripheralName",
|
||||
widget.isSinglePort ? _deviceName : "$_deviceName - $peripheralName",
|
||||
style: GoogleFonts.aBeeZee(),
|
||||
),
|
||||
backgroundColor: Theme.of(context).primaryColorLight,
|
||||
|
||||
Reference in New Issue
Block a user