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