-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
a: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.found in release: 1.23Found to occur in 1.23Found to occur in 1.23frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work on
Description
Steps to Reproduce
- Run this code or simply try flutter_gallery example.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: TextField(
inputFormatters: [DecimalTextInputFormatter(decimalRange: 2),],
),
),
),
),
);
}
}
class DecimalTextInputFormatter extends TextInputFormatter {
DecimalTextInputFormatter({int decimalRange})
: assert(decimalRange == null || decimalRange >= 0,
'DecimalTextInputFormatter declaretion error') {
String dp = (decimalRange != null && decimalRange > 0)
? "([.][0-9]{0,$decimalRange}){0,1}"
: "";
String num = "[0-9]*$dp";
_exp = new RegExp("^($num){0,1}\$");
}
RegExp _exp;
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
print('newValue: $newValue');
print('oldValue: $newValue');
if (_exp.hasMatch(newValue.text)) {
return newValue;
}
return oldValue;
}
}
- Type "1.." in TextField
- The TextField show "1." because "1.." not respect the right pattern
- If you try to delete one char nothing happens because the newValue in formatEditUpdate return "1.." and the delete action remove the last point so the user doesn't see any changes.
Antoher example
- Run the code..
- Type "1.."
- TextField show "1."
- Type "."
- TextField show "1."
- Type "4"
- TextField show "1." , it should show "1.4" but newValue of formatEditUpdate has "1..4" and not respect the pattern
Expected results:
newValue of formatEditUpdate should be the last value returned from formatEditUpdate function.
Actual results:
newValue of formatEditUpdate function retain all char inserted so formatEditUpdate process newValue that is different from that TextField is showing.
Flutter Doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.0, on Mac OS X 10.15.6 19G2021, locale it-IT)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 4.0)
[!] IntelliJ IDEA Ultimate Edition (version 2019.3.3)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
[✓] VS Code (version 1.49.2)
[✓] Connected device (1 available)
! Doctor found issues in 1 category.
daniel-mf, Luxariox, lvyandev and 1ka
Metadata
Metadata
Assignees
Labels
a: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.found in release: 1.23Found to occur in 1.23Found to occur in 1.23frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work on