Unverified Commit 780563ce authored by Shogo Hida's avatar Shogo Hida Committed by GitHub

Add const constructor to TextInputFormatter (#116654)

* Add const constructor to TextInputFormatter

* Fix test

* Add abstract

* Add noSuchMethod
Signed-off-by: 's avatarShogo Hida <shogo.hida@gmail.com>

* Add @override and void
Signed-off-by: 's avatarShogo Hida <shogo.hida@gmail.com>

* Fix text and position of test
Signed-off-by: 's avatarShogo Hida <shogo.hida@gmail.com>
Signed-off-by: 's avatarShogo Hida <shogo.hida@gmail.com>
parent 0eaa83ad
...@@ -88,6 +88,9 @@ enum MaxLengthEnforcement { ...@@ -88,6 +88,9 @@ enum MaxLengthEnforcement {
/// * [FilteringTextInputFormatter], a provided formatter for filtering /// * [FilteringTextInputFormatter], a provided formatter for filtering
/// characters. /// characters.
abstract class TextInputFormatter { abstract class TextInputFormatter {
/// This constructor enables subclasses to provide const constructors so that they can be used in const expressions.
const TextInputFormatter();
/// Called when text is being typed or cut/copy/pasted in the [EditableText]. /// Called when text is being typed or cut/copy/pasted in the [EditableText].
/// ///
/// You can override the resulting text based on the previous text value and /// You can override the resulting text based on the previous text value and
......
...@@ -6,10 +6,26 @@ import 'package:flutter/foundation.dart'; ...@@ -6,10 +6,26 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
class TestTextInputFormatter extends TextInputFormatter {
const TestTextInputFormatter();
@override
void noSuchMethod(Invocation invocation) {
super.noSuchMethod(invocation);
}
}
void main() { void main() {
TextEditingValue testOldValue = TextEditingValue.empty; TextEditingValue testOldValue = TextEditingValue.empty;
TextEditingValue testNewValue = TextEditingValue.empty; TextEditingValue testNewValue = TextEditingValue.empty;
test('test const constructor', () {
const TestTextInputFormatter testValue1 = TestTextInputFormatter();
const TestTextInputFormatter testValue2 = TestTextInputFormatter();
expect(testValue1, same(testValue2));
});
test('withFunction wraps formatting function', () { test('withFunction wraps formatting function', () {
testOldValue = TextEditingValue.empty; testOldValue = TextEditingValue.empty;
testNewValue = TextEditingValue.empty; testNewValue = TextEditingValue.empty;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment