Erweiterungen

This commit is contained in:
Sven committed 2024-02-14 15:54:46 +01:00
1 parent 98581c9a39
commit f9ee90d861
12 files changed
+59 -23

No files matched your search

+29 -3
View File
@@ -117,7 +117,7 @@ class Util {
FocusNode? focusNode,
IconButton? iconButton,
int? maxLines = 1,
TextInputType? type,
TextInputType? textInputType,
List<TextInputFormatter>? formatter,
Function()? onTap,
bool? autofocus}) {
@@ -135,7 +135,7 @@ class Util {
focusNode: focusNode,
maxLines: maxLines,
onTap: onTap,
keyboardType: type,
keyboardType: textInputType,
inputFormatters: formatter,
autofocus: (autofocus != null) ? autofocus : false,
decoration: InputDecoration(
@@ -337,4 +337,30 @@ Future<void> showAlertDialog(BuildContext context, String title, String message)
);
}
);
}
}
class DecimalTextInputFormatter extends TextInputFormatter {
int maxLength;
int decimalPlaces;
DecimalTextInputFormatter({required this.maxLength, required this.decimalPlaces});
@override
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
var text = newValue.text;
String? filteredText = "";
if (text != "") {
RegExp regExp;
if (decimalPlaces > 0) {
regExp = RegExp(r'[0-9]+[,]{0,1}[0-9]{0,' + decimalPlaces.toString() + '}');
} else {
regExp = RegExp(r'[0-9]{0,' + maxLength.toString() +'}');
}
filteredText = regExp.stringMatch(text);
}
return TextEditingValue(text: filteredText ?? oldValue.text);
}
}