@@ -86,55 +86,4 @@ void main() {
86
86
});
87
87
});
88
88
});
89
-
90
- group ('WhitelistingTextInputFormatter' , () {
91
- test ('should return the old value if new value contains non-white-listed character' , () {
92
- const TextEditingValue oldValue = TextEditingValue (text: '12345' );
93
- const TextEditingValue newValue = TextEditingValue (text: '12345@' );
94
-
95
- final WhitelistingTextInputFormatter formatter = WhitelistingTextInputFormatter .digitsOnly;
96
- final TextEditingValue formatted = formatter.formatEditUpdate (oldValue, newValue);
97
-
98
- // assert that we are passing digits only at the first time
99
- expect (oldValue.text, equals ('12345' ));
100
- // The new value is always the oldValue plus a non-digit character (user press @)
101
- expect (newValue.text, equals ('12345@' ));
102
- // we expect that the formatted value returns the oldValue only since the newValue does not
103
- // satisfy the formatter condition (which is, in this case digitsOnly)
104
- expect (formatted.text, equals ('12345' ));
105
- });
106
-
107
- test ('should move the cursor to the right position' , () {
108
- TextEditingValue collapsedValue (String text, int offset) =>
109
- TextEditingValue (
110
- text: text,
111
- selection: TextSelection .collapsed (offset: offset),
112
- );
113
-
114
- TextEditingValue oldValue = collapsedValue ('123' , 0 );
115
- TextEditingValue newValue = collapsedValue ('123456' , 6 );
116
-
117
- final WhitelistingTextInputFormatter formatter =
118
- WhitelistingTextInputFormatter .digitsOnly;
119
- TextEditingValue formatted = formatter.formatEditUpdate (oldValue,
120
- newValue);
121
-
122
- // assert that we are passing digits only at the first time
123
- expect (oldValue.text, equals ('123' ));
124
- // assert that we are passing digits only at the second time
125
- expect (newValue.text, equals ('123456' ));
126
- // assert that cursor is at the end of the text
127
- expect (formatted.selection.baseOffset, equals (6 ));
128
-
129
- // move cursor at the middle of the text and then add the number 9.
130
- oldValue = newValue.copyWith (
131
- selection: const TextSelection .collapsed (offset: 4 ));
132
- newValue = oldValue.copyWith (text: '1239456' );
133
-
134
- formatted = formatter.formatEditUpdate (oldValue, newValue);
135
-
136
- // cursor must be now at fourth position (right after the number 9)
137
- expect (formatted.selection.baseOffset, equals (4 ));
138
- });
139
- });
140
89
}
0 commit comments