2022-03-22 16:23:12 +03:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
|
2022-03-25 17:43:32 +03:00
|
|
|
import '../../app/message.dart';
|
2022-06-13 17:45:26 +03:00
|
|
|
import '../../desktop/models.dart';
|
2022-03-31 12:50:40 +03:00
|
|
|
import '../../widgets/responsive_dialog.dart';
|
2022-07-05 15:53:21 +03:00
|
|
|
import '../../widgets/utf8_text_fields.dart';
|
2022-03-22 16:23:12 +03:00
|
|
|
import '../models.dart';
|
|
|
|
import '../state.dart';
|
|
|
|
import '../../app/models.dart';
|
|
|
|
|
|
|
|
class RenameFingerprintDialog extends ConsumerStatefulWidget {
|
2022-03-28 13:58:45 +03:00
|
|
|
final DevicePath devicePath;
|
2022-03-22 16:23:12 +03:00
|
|
|
final Fingerprint fingerprint;
|
2022-05-12 10:56:55 +03:00
|
|
|
const RenameFingerprintDialog(this.devicePath, this.fingerprint, {super.key});
|
2022-03-22 16:23:12 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<ConsumerStatefulWidget> createState() =>
|
|
|
|
_RenameAccountDialogState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _RenameAccountDialogState extends ConsumerState<RenameFingerprintDialog> {
|
|
|
|
late String _label;
|
|
|
|
_RenameAccountDialogState();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2022-04-04 12:15:38 +03:00
|
|
|
_label = widget.fingerprint.name ?? '';
|
2022-03-22 16:23:12 +03:00
|
|
|
}
|
|
|
|
|
2022-04-06 14:58:09 +03:00
|
|
|
_submit() async {
|
2022-06-13 17:45:26 +03:00
|
|
|
try {
|
|
|
|
final renamed = await ref
|
|
|
|
.read(fingerprintProvider(widget.devicePath).notifier)
|
|
|
|
.renameFingerprint(widget.fingerprint, _label);
|
|
|
|
if (!mounted) return;
|
|
|
|
Navigator.of(context).pop(renamed);
|
|
|
|
showMessage(context, 'Fingerprint renamed');
|
|
|
|
} catch (e) {
|
|
|
|
final String errorMessage;
|
|
|
|
// TODO: Make this cleaner than importing desktop specific RpcError.
|
|
|
|
if (e is RpcError) {
|
|
|
|
errorMessage = e.message;
|
|
|
|
} else {
|
|
|
|
errorMessage = e.toString();
|
|
|
|
}
|
|
|
|
showMessage(
|
|
|
|
context,
|
|
|
|
'Error renaming: $errorMessage',
|
|
|
|
duration: const Duration(seconds: 4),
|
|
|
|
);
|
|
|
|
}
|
2022-04-06 14:58:09 +03:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:23:12 +03:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ResponsiveDialog(
|
|
|
|
title: const Text('Rename fingerprint'),
|
2022-05-12 09:34:51 +03:00
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: _label.isNotEmpty ? _submit : null,
|
|
|
|
child: const Text('Save'),
|
|
|
|
),
|
|
|
|
],
|
2022-03-22 16:23:12 +03:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2022-04-06 14:58:09 +03:00
|
|
|
Text('Rename ${widget.fingerprint.label}?'),
|
2022-03-22 16:23:12 +03:00
|
|
|
const Text('This will change the label of the fingerprint.'),
|
|
|
|
TextFormField(
|
|
|
|
initialValue: _label,
|
|
|
|
maxLength: 15,
|
2022-07-05 15:53:21 +03:00
|
|
|
inputFormatters: [limitBytesLength(15)],
|
|
|
|
buildCounter: buildCountersFor(_label),
|
2022-03-22 16:23:12 +03:00
|
|
|
decoration: const InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
labelText: 'Label',
|
2022-06-09 12:23:34 +03:00
|
|
|
prefixIcon: Icon(Icons.fingerprint_outlined),
|
2022-03-22 16:23:12 +03:00
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_label = value.trim();
|
|
|
|
});
|
|
|
|
},
|
2022-04-06 14:58:09 +03:00
|
|
|
onFieldSubmitted: (_) {
|
|
|
|
if (_label.isNotEmpty) {
|
|
|
|
_submit();
|
|
|
|
}
|
|
|
|
},
|
2022-03-22 16:23:12 +03:00
|
|
|
),
|
|
|
|
]
|
|
|
|
.map((e) => Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
2022-05-12 09:34:51 +03:00
|
|
|
child: e,
|
2022-03-22 16:23:12 +03:00
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|