mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-23 18:58:29 +03:00
f944c9cf86
Also moved the class to lib/widgets/
85 lines
2.5 KiB
Dart
Executable File
85 lines
2.5 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../app/message.dart';
|
|
import '../../widgets/responsive_dialog.dart';
|
|
import '../models.dart';
|
|
import '../state.dart';
|
|
import '../../app/models.dart';
|
|
import '../../app/state.dart';
|
|
|
|
class RenameFingerprintDialog extends ConsumerStatefulWidget {
|
|
final DevicePath devicePath;
|
|
final Fingerprint fingerprint;
|
|
const RenameFingerprintDialog(this.devicePath, this.fingerprint, {Key? key})
|
|
: super(key: key);
|
|
|
|
@override
|
|
ConsumerState<ConsumerStatefulWidget> createState() =>
|
|
_RenameAccountDialogState();
|
|
}
|
|
|
|
class _RenameAccountDialogState extends ConsumerState<RenameFingerprintDialog> {
|
|
late String _label;
|
|
_RenameAccountDialogState();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_label = widget.fingerprint.label;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// If current device changes, we need to pop back to the main Page.
|
|
ref.listen<DeviceNode?>(currentDeviceProvider, (previous, next) {
|
|
Navigator.of(context).pop();
|
|
});
|
|
|
|
final fingerprint = widget.fingerprint;
|
|
|
|
return ResponsiveDialog(
|
|
title: const Text('Rename fingerprint'),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('Rename ${fingerprint.label}?'),
|
|
const Text('This will change the label of the fingerprint.'),
|
|
TextFormField(
|
|
initialValue: _label,
|
|
maxLength: 15,
|
|
decoration: const InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Label',
|
|
),
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_label = value.trim();
|
|
});
|
|
},
|
|
),
|
|
]
|
|
.map((e) => Padding(
|
|
child: e,
|
|
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
|
))
|
|
.toList(),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: _label.isNotEmpty
|
|
? () async {
|
|
final renamed = await ref
|
|
.read(fingerprintProvider(widget.devicePath).notifier)
|
|
.renameFingerprint(fingerprint, _label);
|
|
Navigator.of(context).pop(renamed);
|
|
showMessage(context, 'Fingerprint renamed');
|
|
}
|
|
: null,
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|