forked from flet-dev/flet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature:
TextField
Input validation (flet-dev#2101)
* add ´InputFilter´ * create textfield utils * update textfield.dart * update return type * remove `regex_string` default * add predefined InputFilters
- Loading branch information
1 parent
5194ba2
commit cebdb22
Showing
4 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flet/src/utils/numbers.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
import '../models/control.dart'; | ||
|
||
FilteringTextInputFormatter? parseInputFilter( | ||
Control control, String propName) { | ||
var v = control.attrString(propName, null); | ||
if (v == null) { | ||
return null; | ||
} | ||
|
||
final j1 = json.decode(v); | ||
return inputFilterFromJSON(j1); | ||
} | ||
|
||
FilteringTextInputFormatter inputFilterFromJSON(dynamic json) { | ||
bool allow = true; | ||
String? regexString = ""; | ||
String? replacementString = ""; | ||
|
||
if (json != null) { | ||
allow = parseBool(json["allow"], true); | ||
regexString = json["regex_string"]?.toString(); | ||
replacementString = json["replacement_string"]?.toString(); | ||
} | ||
|
||
debugPrint( | ||
"Textfield inputFilter - allow: $allow | regexString: $regexString | replacementString: $replacementString"); | ||
|
||
return FilteringTextInputFormatter(RegExp(regexString ?? ""), | ||
allow: allow, replacementString: replacementString ?? ""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters