22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ import 'package:flutter/foundation.dart' ;
56import 'package:flutter/material.dart' ;
67import 'package:flutter/services.dart' ;
78import 'package:flutter_test/flutter_test.dart' ;
89
910import '../widgets/clipboard_utils.dart' ;
1011
12+ class TestMaterialLocalizations extends DefaultMaterialLocalizations {
13+ @override
14+ String formatCompactDate (DateTime date) {
15+ return '${date .month }/${date .day }/${date .year }' ;
16+ }
17+ }
18+
19+ class TestMaterialLocalizationsDelegate extends LocalizationsDelegate <MaterialLocalizations > {
20+ @override
21+ bool isSupported (Locale locale) => true ;
22+
23+ @override
24+ Future <MaterialLocalizations > load (Locale locale) {
25+ return SynchronousFuture <MaterialLocalizations >(TestMaterialLocalizations ());
26+ }
27+
28+ @override
29+ bool shouldReload (TestMaterialLocalizationsDelegate old) => false ;
30+ }
31+
1132void main () {
1233 TestWidgetsFlutterBinding .ensureInitialized ();
1334 final MockClipboard mockClipboard = MockClipboard ();
@@ -27,9 +48,11 @@ void main() {
2748 bool autofocus = false ,
2849 Key ? formKey,
2950 ThemeData ? theme,
51+ Iterable <LocalizationsDelegate <dynamic >>? localizationsDelegates,
3052 }) {
3153 return MaterialApp (
3254 theme: theme ?? ThemeData .from (colorScheme: const ColorScheme .light ()),
55+ localizationsDelegates: localizationsDelegates,
3356 home: Material (
3457 child: Form (
3558 key: formKey,
@@ -300,5 +323,27 @@ void main() {
300323 expect (containerColor, equals (Colors .transparent));
301324 });
302325
326+ testWidgets ('Date text localization' , (WidgetTester tester) async {
327+ final Iterable <LocalizationsDelegate <dynamic >> delegates = < LocalizationsDelegate <dynamic >> [
328+ TestMaterialLocalizationsDelegate (),
329+ DefaultWidgetsLocalizations .delegate,
330+ ];
331+ await tester.pumpWidget (
332+ inputDatePickerField (
333+ localizationsDelegates: delegates,
334+ )
335+ );
336+ await tester.enterText (find.byType (TextField ), '01/01/2022' );
337+ await tester.pumpAndSettle ();
338+
339+ // Verify that the widget can be updated to a new value after the
340+ // entered text was transformed by the localization formatter.
341+ await tester.pumpWidget (
342+ inputDatePickerField (
343+ initialDate: DateTime (2017 ),
344+ localizationsDelegates: delegates,
345+ )
346+ );
347+ });
303348 });
304349}
0 commit comments