Skip to content

Commit

Permalink
Unselect all text field
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyrainynight committed Nov 10, 2021
1 parent 3a7675a commit a0238bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/shared/SystemConsts.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mixin SystemConsts {
static String version = '1.0.2';
static String version = '1.0.3';
}
17 changes: 16 additions & 1 deletion lib/shared/my_converter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class _MyConverterState extends State<MyConverter> {
final TextEditingController doubleUrlEn = TextEditingController();
final TextEditingController doubleUrlDe = TextEditingController();

late List<TextEditingController> controllers;

bool base64EnError = false;
bool base64DeError = false;
bool base64UrlEnError = false;
Expand All @@ -34,6 +36,12 @@ class _MyConverterState extends State<MyConverter> {

double _sizeX = 500;

@override
void initState() {
super.initState();
controllers = [base64En, base64De, base64UrlEn, base64UrlDe, urlEn, urlDe, doubleUrlEn, doubleUrlDe];
}

@override
Widget build(BuildContext context) {
_sizeX = MediaQuery.of(context).size.width;
Expand Down Expand Up @@ -100,7 +108,7 @@ class _MyConverterState extends State<MyConverter> {
OutlinedButton(
onPressed: error ? null : () {
Clipboard.setData(ClipboardData(text: controller.text));
// todo: unselect all text fields
clearSelection();
controller.selection = TextSelection(baseOffset: 0, extentOffset: controller.value.text.length);
},
style: buttonStyle,
Expand All @@ -127,6 +135,7 @@ class _MyConverterState extends State<MyConverter> {
readOnly: true,
controller: controller,
onTap: () {
clearSelection();
controller.selection = TextSelection(baseOffset: 0, extentOffset: controller.value.text.length);
},
),
Expand Down Expand Up @@ -218,4 +227,10 @@ class _MyConverterState extends State<MyConverter> {
doubleUrlEnError = false;
doubleUrlDeError = false;
}

clearSelection() {
for (var c in controllers) {
c.selection = const TextSelection(baseOffset: 0, extentOffset: 0);
}
}
}

0 comments on commit a0238bb

Please sign in to comment.