-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathfolder_dialog.dart
50 lines (46 loc) · 1.4 KB
/
folder_dialog.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'package:flutter/material.dart';
class FolderDialog extends StatefulWidget {
const FolderDialog({super.key});
@override
State<FolderDialog> createState() => _FolderDialogState();
}
class _FolderDialogState extends State<FolderDialog> {
final TextEditingController controller = TextEditingController();
final RegExp folderValidator = RegExp(
r'^[^\s^\x00-\x1f\\?*:"";<>|\/][^\x00-\x1f\\?*:"";<>|\/]*[^\s^\x00-\x1f\\?*:"";<>|\/.]+$',
);
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text("New Folder"),
content: TextField(
autofocus: true,
decoration: const InputDecoration(
hintText: "Folder name",
),
controller: controller,
onSubmitted: (value) {
Navigator.pop(context, value);
},
),
actions: [
TextButton(
child: const Text("Cancel"),
onPressed: () {
Navigator.pop(context);
},
),
ValueListenableBuilder<TextEditingValue>(
valueListenable: controller,
builder: (context, value, __) => TextButton(
onPressed:
value.text.isNotEmpty && folderValidator.hasMatch(value.text)
? () => Navigator.of(context).pop(controller.text)
: null,
child: const Text("Create"),
),
),
],
);
}
}