feat: Implement change device name
This commit is contained in:
parent
9653d0dd7e
commit
bfd3888607
|
@ -159,6 +159,11 @@
|
|||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"changeDeviceName": "Change device name",
|
||||
"@changeDeviceName": {
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"changedTheChatAvatar": "{username} changed the chat avatar",
|
||||
"@changedTheChatAvatar": {
|
||||
"type": "text",
|
||||
|
@ -1718,4 +1723,4 @@
|
|||
"type": "text",
|
||||
"placeholders": {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -56,6 +56,19 @@ class DevicesSettingsState extends State<DevicesSettings> {
|
|||
}
|
||||
}
|
||||
|
||||
void _renameDeviceAction(BuildContext context, Device device) async {
|
||||
final displayName = await SimpleDialogs(context).enterText(
|
||||
hintText: device.displayName,
|
||||
labelText: L10n.of(context).changeDeviceName,
|
||||
);
|
||||
if (displayName == null) return;
|
||||
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
||||
Matrix.of(context)
|
||||
.client
|
||||
.setDeviceMetadata(device.deviceId, displayName: displayName),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -117,6 +130,7 @@ class DevicesSettingsState extends State<DevicesSettings> {
|
|||
itemBuilder: (BuildContext context, int i) =>
|
||||
UserDeviceListItem(
|
||||
devices[i],
|
||||
rename: (d) => _renameDeviceAction(context, d),
|
||||
remove: (d) => _removeDevicesAction(context, [d]),
|
||||
),
|
||||
),
|
||||
|
@ -132,23 +146,34 @@ class DevicesSettingsState extends State<DevicesSettings> {
|
|||
class UserDeviceListItem extends StatelessWidget {
|
||||
final Device userDevice;
|
||||
final Function remove;
|
||||
final Function rename;
|
||||
|
||||
const UserDeviceListItem(this.userDevice, {this.remove, Key key})
|
||||
const UserDeviceListItem(this.userDevice, {this.remove, this.rename, Key key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopupMenuButton(
|
||||
onSelected: (String action) {
|
||||
if (action == 'remove' && remove != null) {
|
||||
remove(userDevice);
|
||||
switch (action) {
|
||||
case 'remove':
|
||||
if (remove != null) remove(userDevice);
|
||||
break;
|
||||
case 'rename':
|
||||
if (rename != null) rename(userDevice);
|
||||
}
|
||||
},
|
||||
itemBuilder: (BuildContext context) => [
|
||||
PopupMenuItem<String>(
|
||||
value: 'rename',
|
||||
child: Text(L10n.of(context).changeDeviceName),
|
||||
),
|
||||
PopupMenuItem<String>(
|
||||
value: 'remove',
|
||||
child: Text(L10n.of(context).removeDevice,
|
||||
style: TextStyle(color: Colors.red)),
|
||||
child: Text(
|
||||
L10n.of(context).removeDevice,
|
||||
style: TextStyle(color: Colors.red),
|
||||
),
|
||||
),
|
||||
],
|
||||
child: ListTile(
|
||||
|
|
Loading…
Reference in a new issue