Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -8,88 +8,98 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Material3 - Nested Localizations', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(MaterialApp( // Creates the outer Localizations widget.
|
||||
theme: ThemeData(useMaterial3: true),
|
||||
home: ListView(
|
||||
children: <Widget>[
|
||||
const LocalizationTracker(key: ValueKey<String>('outer')),
|
||||
Localizations(
|
||||
locale: const Locale('zh', 'CN'),
|
||||
delegates: GlobalMaterialLocalizations.delegates,
|
||||
child: const LocalizationTracker(key: ValueKey<String>('inner')),
|
||||
),
|
||||
],
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
// Creates the outer Localizations widget.
|
||||
theme: ThemeData(useMaterial3: true),
|
||||
home: ListView(
|
||||
children: <Widget>[
|
||||
const LocalizationTracker(key: ValueKey<String>('outer')),
|
||||
Localizations(
|
||||
locale: const Locale('zh', 'CN'),
|
||||
delegates: GlobalMaterialLocalizations.delegates,
|
||||
child: const LocalizationTracker(key: ValueKey<String>('inner')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
// Most localized aspects of the TextTheme text styles are the same for the default US local and
|
||||
// for Chinese for Material3. The baselines for all text styles differ.
|
||||
final LocalizationTrackerState outerTracker = tester.state(find.byKey(const ValueKey<String>('outer'), skipOffstage: false));
|
||||
final LocalizationTrackerState outerTracker = tester.state(
|
||||
find.byKey(const ValueKey<String>('outer'), skipOffstage: false),
|
||||
);
|
||||
expect(outerTracker.textBaseline, TextBaseline.alphabetic);
|
||||
final LocalizationTrackerState innerTracker = tester.state(find.byKey(const ValueKey<String>('inner'), skipOffstage: false));
|
||||
final LocalizationTrackerState innerTracker = tester.state(
|
||||
find.byKey(const ValueKey<String>('inner'), skipOffstage: false),
|
||||
);
|
||||
expect(innerTracker.textBaseline, TextBaseline.ideographic);
|
||||
});
|
||||
|
||||
testWidgets('Material2 - Nested Localizations', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(MaterialApp( // Creates the outer Localizations widget.
|
||||
theme: ThemeData(useMaterial3: false),
|
||||
home: ListView(
|
||||
children: <Widget>[
|
||||
const LocalizationTracker(key: ValueKey<String>('outer')),
|
||||
Localizations(
|
||||
locale: const Locale('zh', 'CN'),
|
||||
delegates: GlobalMaterialLocalizations.delegates,
|
||||
child: const LocalizationTracker(key: ValueKey<String>('inner')),
|
||||
),
|
||||
],
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
// Creates the outer Localizations widget.
|
||||
theme: ThemeData(useMaterial3: false),
|
||||
home: ListView(
|
||||
children: <Widget>[
|
||||
const LocalizationTracker(key: ValueKey<String>('outer')),
|
||||
Localizations(
|
||||
locale: const Locale('zh', 'CN'),
|
||||
delegates: GlobalMaterialLocalizations.delegates,
|
||||
child: const LocalizationTracker(key: ValueKey<String>('inner')),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
// Most localized aspects of the TextTheme text styles are the same for the default US local and
|
||||
// for Chinese for Material2. The baselines for all text styles differ.
|
||||
final LocalizationTrackerState outerTracker = tester.state(find.byKey(const ValueKey<String>('outer'), skipOffstage: false));
|
||||
final LocalizationTrackerState outerTracker = tester.state(
|
||||
find.byKey(const ValueKey<String>('outer'), skipOffstage: false),
|
||||
);
|
||||
expect(outerTracker.textBaseline, TextBaseline.alphabetic);
|
||||
final LocalizationTrackerState innerTracker = tester.state(find.byKey(const ValueKey<String>('inner'), skipOffstage: false));
|
||||
final LocalizationTrackerState innerTracker = tester.state(
|
||||
find.byKey(const ValueKey<String>('inner'), skipOffstage: false),
|
||||
);
|
||||
expect(innerTracker.textBaseline, TextBaseline.ideographic);
|
||||
});
|
||||
|
||||
testWidgets('Localizations is compatible with ChangeNotifier.dispose() called during didChangeDependencies', (WidgetTester tester) async {
|
||||
// PageView calls ScrollPosition.dispose() during didChangeDependencies.
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
supportedLocales: const <Locale>[
|
||||
Locale('en', 'US'),
|
||||
Locale('es', 'ES'),
|
||||
],
|
||||
localizationsDelegates: <LocalizationsDelegate<dynamic>>[
|
||||
_DummyLocalizationsDelegate(),
|
||||
...GlobalMaterialLocalizations.delegates,
|
||||
],
|
||||
home: PageView(),
|
||||
)
|
||||
);
|
||||
testWidgets(
|
||||
'Localizations is compatible with ChangeNotifier.dispose() called during didChangeDependencies',
|
||||
(WidgetTester tester) async {
|
||||
// PageView calls ScrollPosition.dispose() during didChangeDependencies.
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
supportedLocales: const <Locale>[Locale('en', 'US'), Locale('es', 'ES')],
|
||||
localizationsDelegates: <LocalizationsDelegate<dynamic>>[
|
||||
_DummyLocalizationsDelegate(),
|
||||
...GlobalMaterialLocalizations.delegates,
|
||||
],
|
||||
home: PageView(),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.binding.setLocale('es', 'US');
|
||||
await tester.pump();
|
||||
await tester.pumpWidget(Container());
|
||||
});
|
||||
await tester.binding.setLocale('es', 'US');
|
||||
await tester.pump();
|
||||
await tester.pumpWidget(Container());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('Locale without countryCode', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/pull/16782
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
supportedLocales: const <Locale>[
|
||||
Locale('es', 'ES'),
|
||||
Locale('zh'),
|
||||
],
|
||||
supportedLocales: const <Locale>[Locale('es', 'ES'), Locale('zh')],
|
||||
home: Container(),
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
await tester.binding.setLocale('zh', '');
|
||||
await tester.pump();
|
||||
await tester.binding.setLocale('es', 'US');
|
||||
await tester.pump();
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,7 +116,7 @@ class _DummyLocalizationsDelegate extends LocalizationsDelegate<DummyLocalizatio
|
||||
bool shouldReload(_DummyLocalizationsDelegate old) => true;
|
||||
}
|
||||
|
||||
class DummyLocalizations { }
|
||||
class DummyLocalizations {}
|
||||
|
||||
class LocalizationTracker extends StatefulWidget {
|
||||
const LocalizationTracker({super.key});
|
||||
|
||||
@@ -7,16 +7,19 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Test correct month form for CupertinoDatePicker in monthYear mode', (WidgetTester tester) async {
|
||||
testWidgets('Test correct month form for CupertinoDatePicker in monthYear mode', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: Center(
|
||||
child: CupertinoDatePicker(
|
||||
initialDateTime: DateTime(2023, 5),
|
||||
onDateTimeChanged: (_) {},
|
||||
mode: CupertinoDatePickerMode.monthYear,
|
||||
)),
|
||||
child: CupertinoDatePicker(
|
||||
initialDateTime: DateTime(2023, 5),
|
||||
onDateTimeChanged: (_) {},
|
||||
mode: CupertinoDatePickerMode.monthYear,
|
||||
),
|
||||
),
|
||||
),
|
||||
supportedLocales: const <Locale>[Locale('ru', 'RU')],
|
||||
localizationsDelegates: GlobalCupertinoLocalizations.delegates,
|
||||
@@ -26,16 +29,19 @@ void main() {
|
||||
expect(find.text('Май'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('Test correct month form for CupertinoDatePicker in date mode', (WidgetTester tester) async {
|
||||
testWidgets('Test correct month form for CupertinoDatePicker in date mode', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: Center(
|
||||
child: CupertinoDatePicker(
|
||||
initialDateTime: DateTime(2023, 5),
|
||||
onDateTimeChanged: (_) {},
|
||||
mode: CupertinoDatePickerMode.date,
|
||||
)),
|
||||
child: CupertinoDatePicker(
|
||||
initialDateTime: DateTime(2023, 5),
|
||||
onDateTimeChanged: (_) {},
|
||||
mode: CupertinoDatePickerMode.date,
|
||||
),
|
||||
),
|
||||
),
|
||||
supportedLocales: const <Locale>[Locale('ru', 'RU')],
|
||||
localizationsDelegates: GlobalCupertinoLocalizations.delegates,
|
||||
|
||||
@@ -22,7 +22,9 @@ void main() {
|
||||
|
||||
expect(GlobalCupertinoLocalizations.delegate.isSupported(locale), isTrue);
|
||||
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(locale);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
|
||||
expect(localizations.datePickerYear(0), isNotNull);
|
||||
expect(localizations.datePickerYear(1), isNotNull);
|
||||
@@ -107,8 +109,14 @@ void main() {
|
||||
expect(localizations.selectAllButtonLabel, isNotNull);
|
||||
|
||||
expect(localizations.tabSemanticsLabel(tabIndex: 2, tabCount: 5), isNotNull);
|
||||
expect(localizations.tabSemanticsLabel(tabIndex: 2, tabCount: 5), isNot(contains(r'$tabIndex')));
|
||||
expect(localizations.tabSemanticsLabel(tabIndex: 2, tabCount: 5), isNot(contains(r'$tabCount')));
|
||||
expect(
|
||||
localizations.tabSemanticsLabel(tabIndex: 2, tabCount: 5),
|
||||
isNot(contains(r'$tabIndex')),
|
||||
);
|
||||
expect(
|
||||
localizations.tabSemanticsLabel(tabIndex: 2, tabCount: 5),
|
||||
isNot(contains(r'$tabCount')),
|
||||
);
|
||||
expect(() => localizations.tabSemanticsLabel(tabIndex: 0, tabCount: 5), throwsAssertionError);
|
||||
expect(() => localizations.tabSemanticsLabel(tabIndex: 2, tabCount: 0), throwsAssertionError);
|
||||
});
|
||||
@@ -117,7 +125,9 @@ void main() {
|
||||
testWidgets('Spot check French', (WidgetTester tester) async {
|
||||
const Locale locale = Locale('fr');
|
||||
expect(GlobalCupertinoLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(locale);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<CupertinoLocalizationFr>());
|
||||
expect(localizations.alertDialogLabel, 'Alerte');
|
||||
expect(localizations.datePickerHourSemanticsLabel(1), '1 heure');
|
||||
@@ -132,7 +142,9 @@ void main() {
|
||||
testWidgets('Spot check Chinese', (WidgetTester tester) async {
|
||||
const Locale locale = Locale('zh');
|
||||
expect(GlobalCupertinoLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(locale);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<CupertinoLocalizationZh>());
|
||||
expect(localizations.alertDialogLabel, '提醒');
|
||||
expect(localizations.datePickerHourSemanticsLabel(1), '1 点');
|
||||
@@ -145,7 +157,9 @@ void main() {
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/53036.
|
||||
testWidgets('`nb` uses `no` as its synonym when `nb` arb file is not present', (WidgetTester tester) async {
|
||||
testWidgets('`nb` uses `no` as its synonym when `nb` arb file is not present', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final File nbCupertinoArbFile = File(
|
||||
path.join(rootDirectoryPath, 'lib', 'src', 'l10n', 'cupertino_nb.arb'),
|
||||
);
|
||||
@@ -153,11 +167,12 @@ void main() {
|
||||
path.join(rootDirectoryPath, 'lib', 'src', 'l10n', 'cupertino_no.arb'),
|
||||
);
|
||||
|
||||
|
||||
if (noCupertinoArbFile.existsSync() && !nbCupertinoArbFile.existsSync()) {
|
||||
Locale locale = const Locale.fromSubtags(languageCode: 'no');
|
||||
expect(GlobalCupertinoLocalizations.delegate.isSupported(locale), isTrue);
|
||||
CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(locale);
|
||||
CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<CupertinoLocalizationNo>());
|
||||
|
||||
final String pasteButtonLabelNo = localizations.pasteButtonLabel;
|
||||
@@ -176,11 +191,10 @@ void main() {
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/36704.
|
||||
testWidgets('kn arb file should be properly Unicode escaped', (WidgetTester tester) async {
|
||||
final File file = File(
|
||||
path.join(rootDirectoryPath, 'lib', 'src', 'l10n', 'cupertino_kn.arb'),
|
||||
);
|
||||
final File file = File(path.join(rootDirectoryPath, 'lib', 'src', 'l10n', 'cupertino_kn.arb'));
|
||||
|
||||
final Map<String, dynamic> bundle = json.decode(file.readAsStringSync()) as Map<String, dynamic>;
|
||||
final Map<String, dynamic> bundle =
|
||||
json.decode(file.readAsStringSync()) as Map<String, dynamic>;
|
||||
|
||||
// Encodes the arb resource values if they have not already been
|
||||
// encoded.
|
||||
@@ -205,56 +219,70 @@ void main() {
|
||||
testWidgets('Finnish translation for tab label', (WidgetTester tester) async {
|
||||
const Locale locale = Locale('fi');
|
||||
expect(GlobalCupertinoLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(locale);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<CupertinoLocalizationFi>());
|
||||
expect(localizations.tabSemanticsLabel(tabIndex: 1, tabCount: 2), 'Välilehti 1 kautta 2');
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/130874.
|
||||
testWidgets('buildButtonItems builds a localized "No Replacements found" button when no suggestions', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
locale: const Locale('ru'),
|
||||
localizationsDelegates: GlobalCupertinoLocalizations.delegates,
|
||||
supportedLocales: const <Locale>[Locale('en'), Locale('ru')],
|
||||
home: _FakeEditableText()
|
||||
),
|
||||
);
|
||||
final _FakeEditableTextState editableTextState =
|
||||
tester.state(find.byType(_FakeEditableText));
|
||||
final List<ContextMenuButtonItem>? buttonItems =
|
||||
CupertinoSpellCheckSuggestionsToolbar.buildButtonItems(editableTextState);
|
||||
testWidgets(
|
||||
'buildButtonItems builds a localized "No Replacements found" button when no suggestions',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
locale: const Locale('ru'),
|
||||
localizationsDelegates: GlobalCupertinoLocalizations.delegates,
|
||||
supportedLocales: const <Locale>[Locale('en'), Locale('ru')],
|
||||
home: _FakeEditableText(),
|
||||
),
|
||||
);
|
||||
final _FakeEditableTextState editableTextState = tester.state(find.byType(_FakeEditableText));
|
||||
final List<ContextMenuButtonItem>? buttonItems =
|
||||
CupertinoSpellCheckSuggestionsToolbar.buildButtonItems(editableTextState);
|
||||
|
||||
expect(buttonItems, isNotNull);
|
||||
expect(buttonItems, hasLength(1));
|
||||
expect(buttonItems!.first.label, 'Варианты замены не найдены');
|
||||
expect(buttonItems.first.onPressed, isNull);
|
||||
});
|
||||
expect(buttonItems, isNotNull);
|
||||
expect(buttonItems, hasLength(1));
|
||||
expect(buttonItems!.first.label, 'Варианты замены не найдены');
|
||||
expect(buttonItems.first.onPressed, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/141764
|
||||
testWidgets('zh-CN translation for look up label', (WidgetTester tester) async {
|
||||
const Locale locale = Locale('zh');
|
||||
expect(GlobalCupertinoLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(locale);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<CupertinoLocalizationZh>());
|
||||
expect(localizations.lookUpButtonLabel, '查询');
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/pull/151364
|
||||
testWidgets('ko-KR translation for cut, copy, paste label in ButtonLabel', (WidgetTester tester) async {
|
||||
testWidgets('ko-KR translation for cut, copy, paste label in ButtonLabel', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
const Locale locale = Locale('ko');
|
||||
expect(GlobalCupertinoLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(locale);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<CupertinoLocalizationKo>());
|
||||
expect(localizations.cutButtonLabel, '잘라내기');
|
||||
expect(localizations.copyButtonLabel, '복사');
|
||||
expect(localizations.pasteButtonLabel, '붙여넣기');
|
||||
});
|
||||
|
||||
testWidgets('localizations.datePickerDayOfMonth uses the current locale for weekdays', (WidgetTester tester) async {
|
||||
testWidgets('localizations.datePickerDayOfMonth uses the current locale for weekdays', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
const Locale locale = Locale('zh');
|
||||
expect(GlobalCupertinoLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(locale);
|
||||
final CupertinoLocalizations localizations = await GlobalCupertinoLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<CupertinoLocalizationZh>());
|
||||
expect(localizations.datePickerDayOfMonth(1), '1日');
|
||||
expect(localizations.datePickerDayOfMonth(1, 2), '周二 1日');
|
||||
@@ -262,13 +290,14 @@ void main() {
|
||||
}
|
||||
|
||||
class _FakeEditableText extends EditableText {
|
||||
_FakeEditableText() : super(
|
||||
controller: TextEditingController(),
|
||||
focusNode: FocusNode(),
|
||||
backgroundCursorColor: CupertinoColors.white,
|
||||
cursorColor: CupertinoColors.white,
|
||||
style: const TextStyle(),
|
||||
);
|
||||
_FakeEditableText()
|
||||
: super(
|
||||
controller: TextEditingController(),
|
||||
focusNode: FocusNode(),
|
||||
backgroundCursorColor: CupertinoColors.white,
|
||||
cursorColor: CupertinoColors.white,
|
||||
style: const TextStyle(),
|
||||
);
|
||||
|
||||
@override
|
||||
_FakeEditableTextState createState() => _FakeEditableTextState();
|
||||
@@ -282,12 +311,6 @@ class _FakeEditableTextState extends EditableTextState {
|
||||
|
||||
@override
|
||||
SuggestionSpan? findSuggestionSpanAtCursorIndex(int cursorIndex) {
|
||||
return const SuggestionSpan(
|
||||
TextRange(
|
||||
start: 0,
|
||||
end: 0,
|
||||
),
|
||||
<String>[],
|
||||
);
|
||||
return const SuggestionSpan(TextRange(start: 0, end: 0), <String>[]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ void main() {
|
||||
// Tests a different first day of week.
|
||||
const Locale('ru', 'RU'): <String, dynamic>{
|
||||
'textDirection': TextDirection.ltr,
|
||||
'expectedDaysOfWeek': <String>['В', 'П', 'В', 'С', 'Ч', 'П', 'С',],
|
||||
'expectedDaysOfWeek': <String>['В', 'П', 'В', 'С', 'Ч', 'П', 'С'],
|
||||
'expectedDaysOfMonth': List<String>.generate(30, (int i) => '${i + 1}'),
|
||||
'expectedMonthYearHeader': 'сентябрь 2017 г.',
|
||||
},
|
||||
@@ -52,18 +52,26 @@ void main() {
|
||||
|
||||
for (final Locale locale in testLocales.keys) {
|
||||
testWidgets('shows dates for $locale', (WidgetTester tester) async {
|
||||
final List<String> expectedDaysOfWeek = testLocales[locale]!['expectedDaysOfWeek'] as List<String>;
|
||||
final List<String> expectedDaysOfMonth = testLocales[locale]!['expectedDaysOfMonth'] as List<String>;
|
||||
final String expectedMonthYearHeader = testLocales[locale]!['expectedMonthYearHeader'] as String;
|
||||
final List<String> expectedDaysOfWeek =
|
||||
testLocales[locale]!['expectedDaysOfWeek'] as List<String>;
|
||||
final List<String> expectedDaysOfMonth =
|
||||
testLocales[locale]!['expectedDaysOfMonth'] as List<String>;
|
||||
final String expectedMonthYearHeader =
|
||||
testLocales[locale]!['expectedMonthYearHeader'] as String;
|
||||
final TextDirection textDirection = testLocales[locale]!['textDirection'] as TextDirection;
|
||||
final DateTime baseDate = DateTime(2017, 9, 27);
|
||||
|
||||
await _pumpBoilerplate(tester, CalendarDatePicker(
|
||||
initialDate: baseDate,
|
||||
firstDate: baseDate.subtract(const Duration(days: 90)),
|
||||
lastDate: baseDate.add(const Duration(days: 90)),
|
||||
onDateChanged: (DateTime newValue) {},
|
||||
), locale: locale, textDirection: textDirection);
|
||||
await _pumpBoilerplate(
|
||||
tester,
|
||||
CalendarDatePicker(
|
||||
initialDate: baseDate,
|
||||
firstDate: baseDate.subtract(const Duration(days: 90)),
|
||||
lastDate: baseDate.add(const Duration(days: 90)),
|
||||
onDateChanged: (DateTime newValue) {},
|
||||
),
|
||||
locale: locale,
|
||||
textDirection: textDirection,
|
||||
);
|
||||
|
||||
expect(find.text(expectedMonthYearHeader), findsOneWidget);
|
||||
|
||||
@@ -73,7 +81,10 @@ void main() {
|
||||
|
||||
Offset? previousCellOffset;
|
||||
for (final String dayOfMonth in expectedDaysOfMonth) {
|
||||
final Finder dayCell = find.descendant(of: find.byType(GridView), matching: find.text(dayOfMonth));
|
||||
final Finder dayCell = find.descendant(
|
||||
of: find.byType(GridView),
|
||||
matching: find.text(dayOfMonth),
|
||||
);
|
||||
expect(dayCell, findsOneWidget);
|
||||
|
||||
// Check that cells are correctly positioned relative to each other,
|
||||
@@ -81,9 +92,17 @@ void main() {
|
||||
final Offset offset = tester.getCenter(dayCell);
|
||||
if (previousCellOffset != null) {
|
||||
if (textDirection == TextDirection.ltr) {
|
||||
expect(offset.dx > previousCellOffset.dx && offset.dy == previousCellOffset.dy || offset.dy > previousCellOffset.dy, true);
|
||||
expect(
|
||||
offset.dx > previousCellOffset.dx && offset.dy == previousCellOffset.dy ||
|
||||
offset.dy > previousCellOffset.dy,
|
||||
true,
|
||||
);
|
||||
} else {
|
||||
expect(offset.dx < previousCellOffset.dx && offset.dy == previousCellOffset.dy || offset.dy > previousCellOffset.dy, true);
|
||||
expect(
|
||||
offset.dx < previousCellOffset.dx && offset.dy == previousCellOffset.dy ||
|
||||
offset.dy > previousCellOffset.dy,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
previousCellOffset = offset;
|
||||
@@ -97,10 +116,7 @@ void main() {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(useMaterial3: false),
|
||||
locale: const Locale('en', 'US'),
|
||||
supportedLocales: const <Locale>[
|
||||
Locale('en', 'US'),
|
||||
Locale('fr', 'CA'),
|
||||
],
|
||||
supportedLocales: const <Locale>[Locale('en', 'US'), Locale('fr', 'CA')],
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Material(
|
||||
child: Builder(
|
||||
@@ -129,14 +145,8 @@ void main() {
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
Localizations.localeOf(getPicker()),
|
||||
const Locale('fr', 'CA'),
|
||||
);
|
||||
expect(
|
||||
Directionality.of(getPicker()),
|
||||
TextDirection.ltr,
|
||||
);
|
||||
expect(Localizations.localeOf(getPicker()), const Locale('fr', 'CA'));
|
||||
expect(Directionality.of(getPicker()), TextDirection.ltr);
|
||||
|
||||
await tester.tap(find.text('ANNULER'));
|
||||
});
|
||||
@@ -146,10 +156,7 @@ void main() {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(useMaterial3: true),
|
||||
locale: const Locale('en', 'US'),
|
||||
supportedLocales: const <Locale>[
|
||||
Locale('en', 'US'),
|
||||
Locale('fr', 'CA'),
|
||||
],
|
||||
supportedLocales: const <Locale>[Locale('en', 'US'), Locale('fr', 'CA')],
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Material(
|
||||
child: Builder(
|
||||
@@ -178,19 +185,15 @@ void main() {
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
Localizations.localeOf(getPicker()),
|
||||
const Locale('fr', 'CA'),
|
||||
);
|
||||
expect(
|
||||
Directionality.of(getPicker()),
|
||||
TextDirection.ltr,
|
||||
);
|
||||
expect(Localizations.localeOf(getPicker()), const Locale('fr', 'CA'));
|
||||
expect(Directionality.of(getPicker()), TextDirection.ltr);
|
||||
|
||||
await tester.tap(find.text('Annuler'));
|
||||
});
|
||||
|
||||
testWidgets('Material2 - textDirection parameter overrides ambient textDirection', (WidgetTester tester) async {
|
||||
testWidgets('Material2 - textDirection parameter overrides ambient textDirection', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
Widget buildFrame() {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(useMaterial3: false),
|
||||
@@ -222,15 +225,14 @@ void main() {
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
Directionality.of(getPicker()),
|
||||
TextDirection.rtl,
|
||||
);
|
||||
expect(Directionality.of(getPicker()), TextDirection.rtl);
|
||||
|
||||
await tester.tap(find.text('CANCEL'));
|
||||
});
|
||||
|
||||
testWidgets('Material3 - textDirection parameter overrides ambient textDirection', (WidgetTester tester) async {
|
||||
testWidgets('Material3 - textDirection parameter overrides ambient textDirection', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
Widget buildFrame() {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(useMaterial3: true),
|
||||
@@ -262,23 +264,19 @@ void main() {
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
Directionality.of(getPicker()),
|
||||
TextDirection.rtl,
|
||||
);
|
||||
expect(Directionality.of(getPicker()), TextDirection.rtl);
|
||||
|
||||
await tester.tap(find.text('Cancel'));
|
||||
});
|
||||
|
||||
testWidgets('Material2 - textDirection parameter takes precedence over locale parameter', (WidgetTester tester) async {
|
||||
testWidgets('Material2 - textDirection parameter takes precedence over locale parameter', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
Widget buildFrame() {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(useMaterial3: false),
|
||||
locale: const Locale('en', 'US'),
|
||||
supportedLocales: const <Locale>[
|
||||
Locale('en', 'US'),
|
||||
Locale('fr', 'CA'),
|
||||
],
|
||||
supportedLocales: const <Locale>[Locale('en', 'US'), Locale('fr', 'CA')],
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Material(
|
||||
child: Builder(
|
||||
@@ -308,28 +306,21 @@ void main() {
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(
|
||||
Localizations.localeOf(getPicker()),
|
||||
const Locale('fr', 'CA'),
|
||||
);
|
||||
expect(Localizations.localeOf(getPicker()), const Locale('fr', 'CA'));
|
||||
|
||||
expect(
|
||||
Directionality.of(getPicker()),
|
||||
TextDirection.rtl,
|
||||
);
|
||||
expect(Directionality.of(getPicker()), TextDirection.rtl);
|
||||
|
||||
await tester.tap(find.text('ANNULER'));
|
||||
});
|
||||
|
||||
testWidgets('Material3 - textDirection parameter takes precedence over locale parameter', (WidgetTester tester) async {
|
||||
testWidgets('Material3 - textDirection parameter takes precedence over locale parameter', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
Widget buildFrame() {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(useMaterial3: true),
|
||||
locale: const Locale('en', 'US'),
|
||||
supportedLocales: const <Locale>[
|
||||
Locale('en', 'US'),
|
||||
Locale('fr', 'CA'),
|
||||
],
|
||||
supportedLocales: const <Locale>[Locale('en', 'US'), Locale('fr', 'CA')],
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Material(
|
||||
child: Builder(
|
||||
@@ -359,15 +350,9 @@ void main() {
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
expect(
|
||||
Localizations.localeOf(getPicker()),
|
||||
const Locale('fr', 'CA'),
|
||||
);
|
||||
expect(Localizations.localeOf(getPicker()), const Locale('fr', 'CA'));
|
||||
|
||||
expect(
|
||||
Directionality.of(getPicker()),
|
||||
TextDirection.rtl,
|
||||
);
|
||||
expect(Directionality.of(getPicker()), TextDirection.rtl);
|
||||
|
||||
await tester.tap(find.text('Annuler'));
|
||||
});
|
||||
@@ -405,7 +390,7 @@ void main() {
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -432,7 +417,6 @@ void main() {
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Future<void> _pumpBoilerplate(
|
||||
@@ -441,16 +425,16 @@ Future<void> _pumpBoilerplate(
|
||||
Locale locale = const Locale('en', 'US'),
|
||||
TextDirection textDirection = TextDirection.ltr,
|
||||
}) async {
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Localizations(
|
||||
locale: locale,
|
||||
delegates: GlobalMaterialLocalizations.delegates,
|
||||
child: Material(
|
||||
child: child,
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Localizations(
|
||||
locale: locale,
|
||||
delegates: GlobalMaterialLocalizations.delegates,
|
||||
child: Material(child: child),
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,13 +13,15 @@ void main() {
|
||||
group(GlobalMaterialLocalizations, () {
|
||||
test('uses exact locale when exists', () async {
|
||||
final GlobalMaterialLocalizations localizations =
|
||||
await GlobalMaterialLocalizations.delegate.load(const Locale('pt', 'PT')) as GlobalMaterialLocalizations;
|
||||
await GlobalMaterialLocalizations.delegate.load(const Locale('pt', 'PT'))
|
||||
as GlobalMaterialLocalizations;
|
||||
expect(localizations.formatDecimal(10000), '10\u00A0000');
|
||||
});
|
||||
|
||||
test('falls back to language code when exact locale is missing', () async {
|
||||
final GlobalMaterialLocalizations localizations =
|
||||
await GlobalMaterialLocalizations.delegate.load(const Locale('pt', 'XX')) as GlobalMaterialLocalizations;
|
||||
await GlobalMaterialLocalizations.delegate.load(const Locale('pt', 'XX'))
|
||||
as GlobalMaterialLocalizations;
|
||||
expect(localizations.formatDecimal(10000), '10.000');
|
||||
});
|
||||
|
||||
@@ -32,120 +34,225 @@ void main() {
|
||||
group('formatHour', () {
|
||||
Future<String> formatHour(WidgetTester tester, Locale locale, TimeOfDay timeOfDay) async {
|
||||
final Completer<String> completer = Completer<String>();
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
supportedLocales: <Locale>[locale],
|
||||
locale: locale,
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
completer.complete(MaterialLocalizations.of(context).formatHour(timeOfDay));
|
||||
return Container();
|
||||
}),
|
||||
));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
supportedLocales: <Locale>[locale],
|
||||
locale: locale,
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
completer.complete(MaterialLocalizations.of(context).formatHour(timeOfDay));
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
testWidgets('formats h', (WidgetTester tester) async {
|
||||
expect(await formatHour(tester, const Locale('en', 'US'), const TimeOfDay(hour: 10, minute: 0)), '10');
|
||||
expect(await formatHour(tester, const Locale('en', 'US'), const TimeOfDay(hour: 20, minute: 0)), '8');
|
||||
expect(
|
||||
await formatHour(tester, const Locale('en', 'US'), const TimeOfDay(hour: 10, minute: 0)),
|
||||
'10',
|
||||
);
|
||||
expect(
|
||||
await formatHour(tester, const Locale('en', 'US'), const TimeOfDay(hour: 20, minute: 0)),
|
||||
'8',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('formats HH', (WidgetTester tester) async {
|
||||
expect(await formatHour(tester, const Locale('de'), const TimeOfDay(hour: 9, minute: 0)), '09');
|
||||
expect(await formatHour(tester, const Locale('de'), const TimeOfDay(hour: 20, minute: 0)), '20');
|
||||
expect(
|
||||
await formatHour(tester, const Locale('de'), const TimeOfDay(hour: 9, minute: 0)),
|
||||
'09',
|
||||
);
|
||||
expect(
|
||||
await formatHour(tester, const Locale('de'), const TimeOfDay(hour: 20, minute: 0)),
|
||||
'20',
|
||||
);
|
||||
|
||||
expect(await formatHour(tester, const Locale('en', 'GB'), const TimeOfDay(hour: 9, minute: 0)), '09');
|
||||
expect(await formatHour(tester, const Locale('en', 'GB'), const TimeOfDay(hour: 20, minute: 0)), '20');
|
||||
expect(
|
||||
await formatHour(tester, const Locale('en', 'GB'), const TimeOfDay(hour: 9, minute: 0)),
|
||||
'09',
|
||||
);
|
||||
expect(
|
||||
await formatHour(tester, const Locale('en', 'GB'), const TimeOfDay(hour: 20, minute: 0)),
|
||||
'20',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('formats H', (WidgetTester tester) async {
|
||||
expect(await formatHour(tester, const Locale('es'), const TimeOfDay(hour: 9, minute: 0)), '9');
|
||||
expect(await formatHour(tester, const Locale('es'), const TimeOfDay(hour: 20, minute: 0)), '20');
|
||||
expect(
|
||||
await formatHour(tester, const Locale('es'), const TimeOfDay(hour: 9, minute: 0)),
|
||||
'9',
|
||||
);
|
||||
expect(
|
||||
await formatHour(tester, const Locale('es'), const TimeOfDay(hour: 20, minute: 0)),
|
||||
'20',
|
||||
);
|
||||
|
||||
expect(await formatHour(tester, const Locale('fa'), const TimeOfDay(hour: 9, minute: 0)), '۹');
|
||||
expect(await formatHour(tester, const Locale('fa'), const TimeOfDay(hour: 20, minute: 0)), '۲۰');
|
||||
expect(
|
||||
await formatHour(tester, const Locale('fa'), const TimeOfDay(hour: 9, minute: 0)),
|
||||
'۹',
|
||||
);
|
||||
expect(
|
||||
await formatHour(tester, const Locale('fa'), const TimeOfDay(hour: 20, minute: 0)),
|
||||
'۲۰',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('formatMinute', () {
|
||||
test('formats English', () async {
|
||||
final GlobalMaterialLocalizations localizations =
|
||||
await GlobalMaterialLocalizations.delegate.load(const Locale('en', 'US')) as GlobalMaterialLocalizations;
|
||||
await GlobalMaterialLocalizations.delegate.load(const Locale('en', 'US'))
|
||||
as GlobalMaterialLocalizations;
|
||||
expect(localizations.formatMinute(const TimeOfDay(hour: 1, minute: 32)), '32');
|
||||
});
|
||||
});
|
||||
|
||||
group('formatTimeOfDay', () {
|
||||
Future<String> formatTimeOfDay(WidgetTester tester, Locale locale, TimeOfDay timeOfDay) async {
|
||||
Future<String> formatTimeOfDay(
|
||||
WidgetTester tester,
|
||||
Locale locale,
|
||||
TimeOfDay timeOfDay,
|
||||
) async {
|
||||
final Completer<String> completer = Completer<String>();
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
supportedLocales: <Locale>[locale],
|
||||
locale: locale,
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
completer.complete(MaterialLocalizations.of(context).formatTimeOfDay(timeOfDay));
|
||||
return Container();
|
||||
}),
|
||||
));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
supportedLocales: <Locale>[locale],
|
||||
locale: locale,
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
completer.complete(MaterialLocalizations.of(context).formatTimeOfDay(timeOfDay));
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
testWidgets('formats ${TimeOfDayFormat.h_colon_mm_space_a}', (WidgetTester tester) async {
|
||||
expect(await formatTimeOfDay(tester, const Locale('en'), const TimeOfDay(hour: 9, minute: 32)), '9:32 AM');
|
||||
expect(await formatTimeOfDay(tester, const Locale('en'), const TimeOfDay(hour: 20, minute: 32)), '8:32 PM');
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('en'), const TimeOfDay(hour: 9, minute: 32)),
|
||||
'9:32 AM',
|
||||
);
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('en'), const TimeOfDay(hour: 20, minute: 32)),
|
||||
'8:32 PM',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('formats ${TimeOfDayFormat.HH_colon_mm}', (WidgetTester tester) async {
|
||||
expect(await formatTimeOfDay(tester, const Locale('de'), const TimeOfDay(hour: 9, minute: 32)), '09:32');
|
||||
expect(await formatTimeOfDay(tester, const Locale('en', 'ZA'), const TimeOfDay(hour: 9, minute: 32)), '09:32');
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('de'), const TimeOfDay(hour: 9, minute: 32)),
|
||||
'09:32',
|
||||
);
|
||||
expect(
|
||||
await formatTimeOfDay(
|
||||
tester,
|
||||
const Locale('en', 'ZA'),
|
||||
const TimeOfDay(hour: 9, minute: 32),
|
||||
),
|
||||
'09:32',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('formats ${TimeOfDayFormat.H_colon_mm}', (WidgetTester tester) async {
|
||||
expect(await formatTimeOfDay(tester, const Locale('es'), const TimeOfDay(hour: 9, minute: 32)), '9:32');
|
||||
expect(await formatTimeOfDay(tester, const Locale('es'), const TimeOfDay(hour: 20, minute: 32)), '20:32');
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('es'), const TimeOfDay(hour: 9, minute: 32)),
|
||||
'9:32',
|
||||
);
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('es'), const TimeOfDay(hour: 20, minute: 32)),
|
||||
'20:32',
|
||||
);
|
||||
|
||||
expect(await formatTimeOfDay(tester, const Locale('ja'), const TimeOfDay(hour: 9, minute: 32)), '9:32');
|
||||
expect(await formatTimeOfDay(tester, const Locale('ja'), const TimeOfDay(hour: 20, minute: 32)), '20:32');
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('ja'), const TimeOfDay(hour: 9, minute: 32)),
|
||||
'9:32',
|
||||
);
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('ja'), const TimeOfDay(hour: 20, minute: 32)),
|
||||
'20:32',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('formats ${TimeOfDayFormat.HH_dot_mm}', (WidgetTester tester) async {
|
||||
expect(await formatTimeOfDay(tester, const Locale('fi'), const TimeOfDay(hour: 20, minute: 32)), '20.32');
|
||||
expect(await formatTimeOfDay(tester, const Locale('fi'), const TimeOfDay(hour: 9, minute: 32)), '09.32');
|
||||
expect(await formatTimeOfDay(tester, const Locale('da'), const TimeOfDay(hour: 9, minute: 32)), '09.32');
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('fi'), const TimeOfDay(hour: 20, minute: 32)),
|
||||
'20.32',
|
||||
);
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('fi'), const TimeOfDay(hour: 9, minute: 32)),
|
||||
'09.32',
|
||||
);
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('da'), const TimeOfDay(hour: 9, minute: 32)),
|
||||
'09.32',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('formats ${TimeOfDayFormat.frenchCanadian}', (WidgetTester tester) async {
|
||||
expect(await formatTimeOfDay(tester, const Locale('fr', 'CA'), const TimeOfDay(hour: 9, minute: 32)), '09 h 32');
|
||||
expect(
|
||||
await formatTimeOfDay(
|
||||
tester,
|
||||
const Locale('fr', 'CA'),
|
||||
const TimeOfDay(hour: 9, minute: 32),
|
||||
),
|
||||
'09 h 32',
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('formats ${TimeOfDayFormat.a_space_h_colon_mm}', (WidgetTester tester) async {
|
||||
expect(await formatTimeOfDay(tester, const Locale('zh'), const TimeOfDay(hour: 9, minute: 32)), '上午 9:32');
|
||||
expect(await formatTimeOfDay(tester, const Locale('ta'), const TimeOfDay(hour: 9, minute: 32)), '9:32 AM');
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('zh'), const TimeOfDay(hour: 9, minute: 32)),
|
||||
'上午 9:32',
|
||||
);
|
||||
expect(
|
||||
await formatTimeOfDay(tester, const Locale('ta'), const TimeOfDay(hour: 9, minute: 32)),
|
||||
'9:32 AM',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('date formatters', () {
|
||||
Future<Map<DateType, String>> formatDate(WidgetTester tester, Locale locale, DateTime dateTime) async {
|
||||
Future<Map<DateType, String>> formatDate(
|
||||
WidgetTester tester,
|
||||
Locale locale,
|
||||
DateTime dateTime,
|
||||
) async {
|
||||
final Completer<Map<DateType, String>> completer = Completer<Map<DateType, String>>();
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
supportedLocales: <Locale>[locale],
|
||||
locale: locale,
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
completer.complete(<DateType, String>{
|
||||
DateType.year: localizations.formatYear(dateTime),
|
||||
DateType.medium: localizations.formatMediumDate(dateTime),
|
||||
DateType.full: localizations.formatFullDate(dateTime),
|
||||
DateType.monthYear: localizations.formatMonthYear(dateTime),
|
||||
});
|
||||
return Container();
|
||||
}),
|
||||
));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
supportedLocales: <Locale>[locale],
|
||||
locale: locale,
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
|
||||
completer.complete(<DateType, String>{
|
||||
DateType.year: localizations.formatYear(dateTime),
|
||||
DateType.medium: localizations.formatMediumDate(dateTime),
|
||||
DateType.full: localizations.formatFullDate(dateTime),
|
||||
DateType.monthYear: localizations.formatMonthYear(dateTime),
|
||||
});
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
return completer.future;
|
||||
}
|
||||
|
||||
testWidgets('formats dates in English', (WidgetTester tester) async {
|
||||
final Map<DateType, String> formatted = await formatDate(tester, const Locale('en'), DateTime(2018, 8));
|
||||
final Map<DateType, String> formatted = await formatDate(
|
||||
tester,
|
||||
const Locale('en'),
|
||||
DateTime(2018, 8),
|
||||
);
|
||||
expect(formatted[DateType.year], '2018');
|
||||
expect(formatted[DateType.medium], 'Wed, Aug 1');
|
||||
expect(formatted[DateType.full], 'Wednesday, August 1, 2018');
|
||||
@@ -153,7 +260,11 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('formats dates in German', (WidgetTester tester) async {
|
||||
final Map<DateType, String> formatted = await formatDate(tester, const Locale('de'), DateTime(2018, 8));
|
||||
final Map<DateType, String> formatted = await formatDate(
|
||||
tester,
|
||||
const Locale('de'),
|
||||
DateTime(2018, 8),
|
||||
);
|
||||
expect(formatted[DateType.year], '2018');
|
||||
expect(formatted[DateType.medium], 'Mi., 1. Aug.');
|
||||
expect(formatted[DateType.full], 'Mittwoch, 1. August 2018');
|
||||
@@ -161,7 +272,11 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('formats dates in Serbian', (WidgetTester tester) async {
|
||||
final Map<DateType, String> formatted = await formatDate(tester, const Locale('sr'), DateTime(2018, 8));
|
||||
final Map<DateType, String> formatted = await formatDate(
|
||||
tester,
|
||||
const Locale('sr'),
|
||||
DateTime(2018, 8),
|
||||
);
|
||||
expect(formatted[DateType.year], '2018.');
|
||||
expect(formatted[DateType.medium], 'сре 1. авг');
|
||||
expect(formatted[DateType.full], 'среда, 1. август 2018.');
|
||||
@@ -169,8 +284,11 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('formats dates in Serbian (Latin)', (WidgetTester tester) async {
|
||||
final Map<DateType, String> formatted = await formatDate(tester,
|
||||
const Locale.fromSubtags(languageCode:'sr', scriptCode: 'Latn'), DateTime(2018, 8));
|
||||
final Map<DateType, String> formatted = await formatDate(
|
||||
tester,
|
||||
const Locale.fromSubtags(languageCode: 'sr', scriptCode: 'Latn'),
|
||||
DateTime(2018, 8),
|
||||
);
|
||||
expect(formatted[DateType.year], '2018.');
|
||||
expect(formatted[DateType.medium], 'sre 1. avg');
|
||||
expect(formatted[DateType.full], 'sreda, 1. avgust 2018.');
|
||||
@@ -180,32 +298,44 @@ void main() {
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/67644.
|
||||
testWidgets('en_US is initialized correctly by Flutter when DateFormat is used', (WidgetTester tester) async {
|
||||
testWidgets('en_US is initialized correctly by Flutter when DateFormat is used', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
late DateFormat dateFormat;
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
locale: const Locale('en', 'US'),
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
dateFormat = DateFormat('EEE, d MMM yyyy HH:mm:ss', 'en_US');
|
||||
return Container();
|
||||
}),
|
||||
));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
locale: const Locale('en', 'US'),
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
dateFormat = DateFormat('EEE, d MMM yyyy HH:mm:ss', 'en_US');
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(dateFormat.locale, 'en_US');
|
||||
});
|
||||
|
||||
testWidgets('cy is initialized correctly by Flutter when DateFormat is used', (WidgetTester tester) async {
|
||||
testWidgets('cy is initialized correctly by Flutter when DateFormat is used', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
late DateFormat dateFormat;
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
locale: const Locale('cy'),
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Builder(builder: (BuildContext context) {
|
||||
dateFormat = DateFormat.yMMMd('cy');
|
||||
return Container();
|
||||
}),
|
||||
));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
locale: const Locale('cy'),
|
||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
dateFormat = DateFormat.yMMMd('cy');
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(dateFormat.locale, 'cy');
|
||||
expect(dateFormat.format(DateTime(2023, 4, 10, 2, 32)), equals('10 Ebr 2023'));
|
||||
|
||||
@@ -7,12 +7,8 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Test semantics of TabPageSelector in pt-BR',
|
||||
(WidgetTester tester) async {
|
||||
final TabController controller = TabController(
|
||||
vsync: const TestVSync(),
|
||||
length: 2,
|
||||
);
|
||||
testWidgets('Test semantics of TabPageSelector in pt-BR', (WidgetTester tester) async {
|
||||
final TabController controller = TabController(vsync: const TestVSync(), length: 2);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Localizations(
|
||||
@@ -47,8 +43,10 @@ void main() {
|
||||
|
||||
final SemanticsHandle handle = tester.ensureSemantics();
|
||||
|
||||
expect(tester.getSemantics(find.byType(TabPageSelector)),
|
||||
matchesSemantics(label: 'Guia 1 de 2'));
|
||||
expect(
|
||||
tester.getSemantics(find.byType(TabPageSelector)),
|
||||
matchesSemantics(label: 'Guia 1 de 2'),
|
||||
);
|
||||
|
||||
handle.dispose();
|
||||
});
|
||||
|
||||
@@ -7,19 +7,32 @@ import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Material2 - can localize the header in all known formats - portrait', (WidgetTester tester) async {
|
||||
testWidgets('Material2 - can localize the header in all known formats - portrait', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
// Ensure picker is displayed in portrait mode.
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final Finder timeSelectorSeparatorFinder = find.descendant(
|
||||
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator'),
|
||||
matching: find.byType(Text),
|
||||
).first;
|
||||
final Finder hourControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_HourControl');
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_MinuteControl');
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DayPeriodControl');
|
||||
final Finder timeSelectorSeparatorFinder =
|
||||
find
|
||||
.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator',
|
||||
),
|
||||
matching: find.byType(Text),
|
||||
)
|
||||
.first;
|
||||
final Finder hourControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_HourControl',
|
||||
);
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_MinuteControl',
|
||||
);
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_DayPeriodControl',
|
||||
);
|
||||
|
||||
// TODO(yjbanov): also test `HH.mm` (in_ID), `a h:mm` (ko_KR) and `HH:mm น.` (th_TH) when we have .arb files for them
|
||||
final List<Locale> locales = <Locale>[
|
||||
@@ -32,7 +45,12 @@ void main() {
|
||||
];
|
||||
|
||||
for (final Locale locale in locales) {
|
||||
final Offset center = await startPicker(tester, (TimeOfDay? time) { }, locale: locale, useMaterial3: false);
|
||||
final Offset center = await startPicker(
|
||||
tester,
|
||||
(TimeOfDay? time) {},
|
||||
locale: locale,
|
||||
useMaterial3: false,
|
||||
);
|
||||
final Text stringFragmentText = tester.widget(timeSelectorSeparatorFinder);
|
||||
final double hourLeftOffset = tester.getTopLeft(hourControlFinder).dx;
|
||||
final double minuteLeftOffset = tester.getTopLeft(minuteControlFinder).dx;
|
||||
@@ -77,19 +95,32 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Material3 - can localize the header in all known formats - portrait', (WidgetTester tester) async {
|
||||
testWidgets('Material3 - can localize the header in all known formats - portrait', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
// Ensure picker is displayed in portrait mode.
|
||||
tester.view.physicalSize = const Size(400, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final Finder timeSelectorSeparatorFinder = find.descendant(
|
||||
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator'),
|
||||
matching: find.byType(Text),
|
||||
).first;
|
||||
final Finder hourControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_HourControl');
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_MinuteControl');
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DayPeriodControl');
|
||||
final Finder timeSelectorSeparatorFinder =
|
||||
find
|
||||
.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator',
|
||||
),
|
||||
matching: find.byType(Text),
|
||||
)
|
||||
.first;
|
||||
final Finder hourControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_HourControl',
|
||||
);
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_MinuteControl',
|
||||
);
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_DayPeriodControl',
|
||||
);
|
||||
|
||||
// TODO(yjbanov): also test `HH.mm` (in_ID), `a h:mm` (ko_KR) and `HH:mm น.` (th_TH) when we have .arb files for them
|
||||
final List<Locale> locales = <Locale>[
|
||||
@@ -102,7 +133,12 @@ void main() {
|
||||
];
|
||||
|
||||
for (final Locale locale in locales) {
|
||||
final Offset center = await startPicker(tester, (TimeOfDay? time) { }, locale: locale, useMaterial3: true);
|
||||
final Offset center = await startPicker(
|
||||
tester,
|
||||
(TimeOfDay? time) {},
|
||||
locale: locale,
|
||||
useMaterial3: true,
|
||||
);
|
||||
final Text stringFragmentText = tester.widget(timeSelectorSeparatorFinder);
|
||||
final double hourLeftOffset = tester.getTopLeft(hourControlFinder).dx;
|
||||
final double minuteLeftOffset = tester.getTopLeft(minuteControlFinder).dx;
|
||||
@@ -147,19 +183,32 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Material2 - can localize the header in all known formats - landscape', (WidgetTester tester) async {
|
||||
testWidgets('Material2 - can localize the header in all known formats - landscape', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
// Ensure picker is displayed in landscape mode.
|
||||
tester.view.physicalSize = const Size(800, 400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final Finder timeSelectorSeparatorFinder = find.descendant(
|
||||
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator'),
|
||||
matching: find.byType(Text),
|
||||
).first;
|
||||
final Finder hourControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_HourControl');
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_MinuteControl');
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DayPeriodControl');
|
||||
final Finder timeSelectorSeparatorFinder =
|
||||
find
|
||||
.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator',
|
||||
),
|
||||
matching: find.byType(Text),
|
||||
)
|
||||
.first;
|
||||
final Finder hourControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_HourControl',
|
||||
);
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_MinuteControl',
|
||||
);
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_DayPeriodControl',
|
||||
);
|
||||
|
||||
// TODO(yjbanov): also test `HH.mm` (in_ID), `a h:mm` (ko_KR) and `HH:mm น.` (th_TH) when we have .arb files for them
|
||||
final List<Locale> locales = <Locale>[
|
||||
@@ -172,7 +221,12 @@ void main() {
|
||||
];
|
||||
|
||||
for (final Locale locale in locales) {
|
||||
final Offset center = await startPicker(tester, (TimeOfDay? time) { }, locale: locale, useMaterial3: false);
|
||||
final Offset center = await startPicker(
|
||||
tester,
|
||||
(TimeOfDay? time) {},
|
||||
locale: locale,
|
||||
useMaterial3: false,
|
||||
);
|
||||
final Text stringFragmentText = tester.widget(timeSelectorSeparatorFinder);
|
||||
final double hourLeftOffset = tester.getTopLeft(hourControlFinder).dx;
|
||||
final double hourTopOffset = tester.getTopLeft(hourControlFinder).dy;
|
||||
@@ -222,19 +276,32 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Material3 - can localize the header in all known formats - landscape', (WidgetTester tester) async {
|
||||
testWidgets('Material3 - can localize the header in all known formats - landscape', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
// Ensure picker is displayed in landscape mode.
|
||||
tester.view.physicalSize = const Size(800, 400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final Finder timeSelectorSeparatorFinder = find.descendant(
|
||||
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator'),
|
||||
matching: find.byType(Text),
|
||||
).first;
|
||||
final Finder hourControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_HourControl');
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_MinuteControl');
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DayPeriodControl');
|
||||
final Finder timeSelectorSeparatorFinder =
|
||||
find
|
||||
.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator',
|
||||
),
|
||||
matching: find.byType(Text),
|
||||
)
|
||||
.first;
|
||||
final Finder hourControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_HourControl',
|
||||
);
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_MinuteControl',
|
||||
);
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_DayPeriodControl',
|
||||
);
|
||||
|
||||
// TODO(yjbanov): also test `HH.mm` (in_ID), `a h:mm` (ko_KR) and `HH:mm น.` (th_TH) when we have .arb files for them
|
||||
final List<Locale> locales = <Locale>[
|
||||
@@ -247,7 +314,12 @@ void main() {
|
||||
];
|
||||
|
||||
for (final Locale locale in locales) {
|
||||
final Offset center = await startPicker(tester, (TimeOfDay? time) { }, locale: locale, useMaterial3: true);
|
||||
final Offset center = await startPicker(
|
||||
tester,
|
||||
(TimeOfDay? time) {},
|
||||
locale: locale,
|
||||
useMaterial3: true,
|
||||
);
|
||||
final Text stringFragmentText = tester.widget(timeSelectorSeparatorFinder);
|
||||
final double hourLeftOffset = tester.getTopLeft(hourControlFinder).dx;
|
||||
final double hourTopOffset = tester.getTopLeft(hourControlFinder).dy;
|
||||
@@ -297,14 +369,27 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Material2 - can localize input mode in all known formats', (WidgetTester tester) async {
|
||||
final Finder hourControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_HourTextField');
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_MinuteTextField');
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DayPeriodControl');
|
||||
final Finder timeSelectorSeparatorFinder = find.descendant(
|
||||
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator'),
|
||||
matching: find.byType(Text),
|
||||
).first;
|
||||
testWidgets('Material2 - can localize input mode in all known formats', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final Finder hourControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_HourTextField',
|
||||
);
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_MinuteTextField',
|
||||
);
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_DayPeriodControl',
|
||||
);
|
||||
final Finder timeSelectorSeparatorFinder =
|
||||
find
|
||||
.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator',
|
||||
),
|
||||
matching: find.byType(Text),
|
||||
)
|
||||
.first;
|
||||
|
||||
// TODO(yjbanov): also test `HH.mm` (in_ID), `a h:mm` (ko_KR) and `HH:mm น.` (th_TH) when we have .arb files for them
|
||||
final List<Locale> locales = <Locale>[
|
||||
@@ -317,7 +402,14 @@ void main() {
|
||||
];
|
||||
|
||||
for (final Locale locale in locales) {
|
||||
await tester.pumpWidget(_TimePickerLauncher(onChanged: (TimeOfDay? time) { }, locale: locale, entryMode: TimePickerEntryMode.input, useMaterial3 : false));
|
||||
await tester.pumpWidget(
|
||||
_TimePickerLauncher(
|
||||
onChanged: (TimeOfDay? time) {},
|
||||
locale: locale,
|
||||
entryMode: TimePickerEntryMode.input,
|
||||
useMaterial3: false,
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
@@ -365,14 +457,27 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Material3 - can localize input mode in all known formats', (WidgetTester tester) async {
|
||||
final Finder hourControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_HourTextField');
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_MinuteTextField');
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_DayPeriodControl');
|
||||
final Finder timeSelectorSeparatorFinder = find.descendant(
|
||||
of: find.byWidgetPredicate((Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator'),
|
||||
matching: find.byType(Text),
|
||||
).first;
|
||||
testWidgets('Material3 - can localize input mode in all known formats', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final Finder hourControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_HourTextField',
|
||||
);
|
||||
final Finder minuteControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_MinuteTextField',
|
||||
);
|
||||
final Finder dayPeriodControlFinder = find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_DayPeriodControl',
|
||||
);
|
||||
final Finder timeSelectorSeparatorFinder =
|
||||
find
|
||||
.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(Widget w) => '${w.runtimeType}' == '_TimeSelectorSeparator',
|
||||
),
|
||||
matching: find.byType(Text),
|
||||
)
|
||||
.first;
|
||||
|
||||
// TODO(yjbanov): also test `HH.mm` (in_ID), `a h:mm` (ko_KR) and `HH:mm น.` (th_TH) when we have .arb files for them
|
||||
final List<Locale> locales = <Locale>[
|
||||
@@ -385,7 +490,14 @@ void main() {
|
||||
];
|
||||
|
||||
for (final Locale locale in locales) {
|
||||
await tester.pumpWidget(_TimePickerLauncher(onChanged: (TimeOfDay? time) { }, locale: locale, entryMode: TimePickerEntryMode.input, useMaterial3 : true));
|
||||
await tester.pumpWidget(
|
||||
_TimePickerLauncher(
|
||||
onChanged: (TimeOfDay? time) {},
|
||||
locale: locale,
|
||||
entryMode: TimePickerEntryMode.input,
|
||||
useMaterial3: true,
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('X'));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
|
||||
@@ -433,7 +545,9 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Material2 uses single-ring 24-hour dial for all locales', (WidgetTester tester) async {
|
||||
testWidgets('Material2 uses single-ring 24-hour dial for all locales', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
const List<Locale> locales = <Locale>[
|
||||
Locale('en', 'US'), // h
|
||||
Locale('en', 'GB'), // HH
|
||||
@@ -445,7 +559,14 @@ void main() {
|
||||
// DatePicker no matter where you tap the time will be the same.
|
||||
for (int i = 1; i < 10; i++) {
|
||||
TimeOfDay? result;
|
||||
final Offset center = await startPicker(tester, (TimeOfDay? time) { result = time; }, locale: locale, useMaterial3: false);
|
||||
final Offset center = await startPicker(
|
||||
tester,
|
||||
(TimeOfDay? time) {
|
||||
result = time;
|
||||
},
|
||||
locale: locale,
|
||||
useMaterial3: false,
|
||||
);
|
||||
final Size size = tester.getSize(find.byKey(const Key('time-picker-dial')));
|
||||
final double dy = (size.height / 2.0 / 10) * i;
|
||||
await tester.tapAt(Offset(center.dx, center.dy - dy));
|
||||
@@ -455,34 +576,127 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Material3 uses a double-ring 24-hour dial for 24 hour locales', (WidgetTester tester) async {
|
||||
Future<void> testLocale(Locale locale, int startFactor, int endFactor, TimeOfDay expectedTime) async {
|
||||
testWidgets('Material3 uses a double-ring 24-hour dial for 24 hour locales', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
Future<void> testLocale(
|
||||
Locale locale,
|
||||
int startFactor,
|
||||
int endFactor,
|
||||
TimeOfDay expectedTime,
|
||||
) async {
|
||||
// For locales that display 24 hour time, factors 1-5 put the tap on the
|
||||
// inner ring's "12" (the inner ring goes from 12-23). Otherwise the offset
|
||||
// should land on the outer ring's "00".
|
||||
for (int factor = startFactor; factor < endFactor; factor += 1) {
|
||||
TimeOfDay? result;
|
||||
final Offset center = await startPicker(tester, (TimeOfDay? time) { result = time; }, locale: locale, useMaterial3: true);
|
||||
final Offset center = await startPicker(
|
||||
tester,
|
||||
(TimeOfDay? time) {
|
||||
result = time;
|
||||
},
|
||||
locale: locale,
|
||||
useMaterial3: true,
|
||||
);
|
||||
final Size size = tester.getSize(find.byKey(const Key('time-picker-dial')));
|
||||
final double dy = (size.height / 2.0 / 10) * factor;
|
||||
await tester.tapAt(Offset(center.dx, center.dy - dy));
|
||||
await finishPicker(tester);
|
||||
expect(result, equals(expectedTime), reason: 'Failed for locale=$locale with factor=$factor');
|
||||
expect(
|
||||
result,
|
||||
equals(expectedTime),
|
||||
reason: 'Failed for locale=$locale with factor=$factor',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await testLocale(const Locale('en', 'US'), 1, 10, const TimeOfDay(hour: 0, minute: 0)); // 12 hour
|
||||
await testLocale(const Locale('en', 'ES'), 1, 10, const TimeOfDay(hour: 0, minute: 0)); // 12 hour
|
||||
await testLocale(const Locale('en', 'GB'), 1, 5, const TimeOfDay(hour: 12, minute: 0)); // 24 hour, inner ring
|
||||
await testLocale(const Locale('en', 'GB'), 6, 10, const TimeOfDay(hour: 0, minute: 0)); // 24 hour, outer ring
|
||||
await testLocale(
|
||||
const Locale('en', 'US'),
|
||||
1,
|
||||
10,
|
||||
const TimeOfDay(hour: 0, minute: 0),
|
||||
); // 12 hour
|
||||
await testLocale(
|
||||
const Locale('en', 'ES'),
|
||||
1,
|
||||
10,
|
||||
const TimeOfDay(hour: 0, minute: 0),
|
||||
); // 12 hour
|
||||
await testLocale(
|
||||
const Locale('en', 'GB'),
|
||||
1,
|
||||
5,
|
||||
const TimeOfDay(hour: 12, minute: 0),
|
||||
); // 24 hour, inner ring
|
||||
await testLocale(
|
||||
const Locale('en', 'GB'),
|
||||
6,
|
||||
10,
|
||||
const TimeOfDay(hour: 0, minute: 0),
|
||||
); // 24 hour, outer ring
|
||||
});
|
||||
|
||||
const List<String> labels12To11 = <String>['12', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'];
|
||||
const List<String> labels00To22TwoDigit = <String>['00', '02', '04', '06', '08', '10', '12', '14', '16', '18', '20', '22']; // Material 2
|
||||
const List<String> labels00To23TwoDigit = <String>[ // Material 3
|
||||
'00', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'];
|
||||
const List<String> labels12To11 = <String>[
|
||||
'12',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'10',
|
||||
'11',
|
||||
];
|
||||
const List<String> labels00To22TwoDigit = <String>[
|
||||
'00',
|
||||
'02',
|
||||
'04',
|
||||
'06',
|
||||
'08',
|
||||
'10',
|
||||
'12',
|
||||
'14',
|
||||
'16',
|
||||
'18',
|
||||
'20',
|
||||
'22',
|
||||
]; // Material 2
|
||||
const List<String> labels00To23TwoDigit = <String>[
|
||||
// Material 3
|
||||
'00',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'10',
|
||||
'11',
|
||||
'12',
|
||||
'13',
|
||||
'14',
|
||||
'15',
|
||||
'16',
|
||||
'17',
|
||||
'18',
|
||||
'19',
|
||||
'20',
|
||||
'21',
|
||||
'22',
|
||||
'23',
|
||||
];
|
||||
|
||||
Future<void> mediaQueryBoilerplate(WidgetTester tester, {required bool alwaysUse24HourFormat, required bool useMaterial3}) async {
|
||||
Future<void> mediaQueryBoilerplate(
|
||||
WidgetTester tester, {
|
||||
required bool alwaysUse24HourFormat,
|
||||
required bool useMaterial3,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(useMaterial3: useMaterial3),
|
||||
@@ -497,14 +711,19 @@ void main() {
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Navigator(
|
||||
onGenerateRoute: (RouteSettings settings) {
|
||||
return MaterialPageRoute<void>(builder: (BuildContext context) {
|
||||
return TextButton(
|
||||
onPressed: () {
|
||||
showTimePicker(context: context, initialTime: const TimeOfDay(hour: 7, minute: 0));
|
||||
},
|
||||
child: const Text('X'),
|
||||
);
|
||||
});
|
||||
return MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return TextButton(
|
||||
onPressed: () {
|
||||
showTimePicker(
|
||||
context: context,
|
||||
initialTime: const TimeOfDay(hour: 7, minute: 0),
|
||||
);
|
||||
},
|
||||
child: const Text('X'),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -516,10 +735,14 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets('Material2 respects MediaQueryData.alwaysUse24HourFormat == false', (WidgetTester tester) async {
|
||||
await mediaQueryBoilerplate(tester, alwaysUse24HourFormat: false, useMaterial3: false);
|
||||
testWidgets('Material2 respects MediaQueryData.alwaysUse24HourFormat == false', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await mediaQueryBoilerplate(tester, alwaysUse24HourFormat: false, useMaterial3: false);
|
||||
|
||||
final CustomPaint dialPaint = tester.widget(find.byKey(const ValueKey<String>('time-picker-dial')));
|
||||
final CustomPaint dialPaint = tester.widget(
|
||||
find.byKey(const ValueKey<String>('time-picker-dial')),
|
||||
);
|
||||
final dynamic dialPainter = dialPaint.painter;
|
||||
// ignore: avoid_dynamic_calls
|
||||
final List<dynamic> primaryLabels = dialPainter.primaryLabels as List<dynamic>;
|
||||
@@ -542,10 +765,14 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Material3 respects MediaQueryData.alwaysUse24HourFormat == false', (WidgetTester tester) async {
|
||||
await mediaQueryBoilerplate(tester, alwaysUse24HourFormat: false, useMaterial3: true);
|
||||
testWidgets('Material3 respects MediaQueryData.alwaysUse24HourFormat == false', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await mediaQueryBoilerplate(tester, alwaysUse24HourFormat: false, useMaterial3: true);
|
||||
|
||||
final CustomPaint dialPaint = tester.widget(find.byKey(const ValueKey<String>('time-picker-dial')));
|
||||
final CustomPaint dialPaint = tester.widget(
|
||||
find.byKey(const ValueKey<String>('time-picker-dial')),
|
||||
);
|
||||
final dynamic dialPainter = dialPaint.painter;
|
||||
// ignore: avoid_dynamic_calls
|
||||
final List<dynamic> primaryLabels = dialPainter.primaryLabels as List<dynamic>;
|
||||
@@ -568,10 +795,14 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Material3 respects MediaQueryData.alwaysUse24HourFormat == true', (WidgetTester tester) async {
|
||||
testWidgets('Material3 respects MediaQueryData.alwaysUse24HourFormat == true', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await mediaQueryBoilerplate(tester, alwaysUse24HourFormat: true, useMaterial3: true);
|
||||
|
||||
final CustomPaint dialPaint = tester.widget(find.byKey(const ValueKey<String>('time-picker-dial')));
|
||||
final CustomPaint dialPaint = tester.widget(
|
||||
find.byKey(const ValueKey<String>('time-picker-dial')),
|
||||
);
|
||||
final dynamic dialPainter = dialPaint.painter;
|
||||
// ignore: avoid_dynamic_calls
|
||||
final List<dynamic> primaryLabels = dialPainter.primaryLabels as List<dynamic>;
|
||||
@@ -594,10 +825,14 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Material2 respects MediaQueryData.alwaysUse24HourFormat == true', (WidgetTester tester) async {
|
||||
testWidgets('Material2 respects MediaQueryData.alwaysUse24HourFormat == true', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
await mediaQueryBoilerplate(tester, alwaysUse24HourFormat: true, useMaterial3: false);
|
||||
|
||||
final CustomPaint dialPaint = tester.widget(find.byKey(const ValueKey<String>('time-picker-dial')));
|
||||
final CustomPaint dialPaint = tester.widget(
|
||||
find.byKey(const ValueKey<String>('time-picker-dial')),
|
||||
);
|
||||
final dynamic dialPainter = dialPaint.painter;
|
||||
// ignore: avoid_dynamic_calls
|
||||
final List<dynamic> primaryLabels = dialPainter.primaryLabels as List<dynamic>;
|
||||
@@ -621,13 +856,21 @@ void main() {
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/156565
|
||||
testWidgets('AM/PM buttons should be aligned to LTR in Hindi language - Portrait', (WidgetTester tester) async {
|
||||
testWidgets('AM/PM buttons should be aligned to LTR in Hindi language - Portrait', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
const Locale locale = Locale('hi', 'HI');
|
||||
|
||||
final Offset centerPortrait = await startPicker(tester, (TimeOfDay? time) {}, locale: locale, useMaterial3: false, orientation: Orientation.portrait);
|
||||
final Offset centerPortrait = await startPicker(
|
||||
tester,
|
||||
(TimeOfDay? time) {},
|
||||
locale: locale,
|
||||
useMaterial3: false,
|
||||
orientation: Orientation.portrait,
|
||||
);
|
||||
|
||||
final Finder amButtonPortrait = find.text('AM');
|
||||
final Finder pmButtonPortrait = find.text('PM') ;
|
||||
final Finder pmButtonPortrait = find.text('PM');
|
||||
|
||||
final Offset amButtonPositionPortrait = tester.getCenter(amButtonPortrait);
|
||||
final Offset pmButtonPositionPortrait = tester.getCenter(pmButtonPortrait);
|
||||
@@ -637,10 +880,18 @@ void main() {
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/156565
|
||||
testWidgets('AM/PM buttons should be aligned to LTR in Hindi language - Landscape', (WidgetTester tester) async {
|
||||
testWidgets('AM/PM buttons should be aligned to LTR in Hindi language - Landscape', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
const Locale locale = Locale('hi', 'HI');
|
||||
|
||||
final Offset centerLandscape = await startPicker(tester, (TimeOfDay? time) {}, locale: locale, useMaterial3: false, orientation: Orientation.landscape);
|
||||
final Offset centerLandscape = await startPicker(
|
||||
tester,
|
||||
(TimeOfDay? time) {},
|
||||
locale: locale,
|
||||
useMaterial3: false,
|
||||
orientation: Orientation.landscape,
|
||||
);
|
||||
|
||||
final Finder amButtonLandscape = find.text('AM');
|
||||
final Finder pmButtonLandscape = find.text('PM');
|
||||
@@ -682,15 +933,17 @@ class _TimePickerLauncher extends StatelessWidget {
|
||||
return ElevatedButton(
|
||||
child: const Text('X'),
|
||||
onPressed: () async {
|
||||
onChanged?.call(await showTimePicker(
|
||||
context: context,
|
||||
initialEntryMode: entryMode,
|
||||
orientation: orientation,
|
||||
initialTime: const TimeOfDay(hour: 7, minute: 0),
|
||||
));
|
||||
onChanged?.call(
|
||||
await showTimePicker(
|
||||
context: context,
|
||||
initialEntryMode: entryMode,
|
||||
orientation: orientation,
|
||||
initialTime: const TimeOfDay(hour: 7, minute: 0),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -701,9 +954,9 @@ class _TimePickerLauncher extends StatelessWidget {
|
||||
Future<Offset> startPicker(
|
||||
WidgetTester tester,
|
||||
ValueChanged<TimeOfDay?> onChanged, {
|
||||
Locale locale = const Locale('en', 'US'),
|
||||
bool? useMaterial3,
|
||||
Orientation? orientation,
|
||||
Locale locale = const Locale('en', 'US'),
|
||||
bool? useMaterial3,
|
||||
Orientation? orientation,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
_TimePickerLauncher(
|
||||
@@ -719,7 +972,9 @@ Future<Offset> startPicker(
|
||||
}
|
||||
|
||||
Future<void> finishPicker(WidgetTester tester) async {
|
||||
final MaterialLocalizations materialLocalizations = MaterialLocalizations.of(tester.element(find.byType(ElevatedButton)));
|
||||
final MaterialLocalizations materialLocalizations = MaterialLocalizations.of(
|
||||
tester.element(find.byType(ElevatedButton)),
|
||||
);
|
||||
await tester.tap(find.text(materialLocalizations.okButtonLabel));
|
||||
await tester.pumpAndSettle(const Duration(seconds: 1));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ void main() {
|
||||
|
||||
expect(GlobalMaterialLocalizations.delegate.isSupported(locale), isTrue);
|
||||
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(locale);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
|
||||
expect(localizations.openAppDrawerTooltip, isNotNull);
|
||||
expect(localizations.backButtonTooltip, isNotNull);
|
||||
@@ -63,9 +65,18 @@ void main() {
|
||||
expect(localizations.remainingTextFieldCharacterCount(0), isNotNull);
|
||||
expect(localizations.remainingTextFieldCharacterCount(1), isNotNull);
|
||||
expect(localizations.remainingTextFieldCharacterCount(10), isNotNull);
|
||||
expect(localizations.remainingTextFieldCharacterCount(0), isNot(contains(r'$remainingCount')));
|
||||
expect(localizations.remainingTextFieldCharacterCount(1), isNot(contains(r'$remainingCount')));
|
||||
expect(localizations.remainingTextFieldCharacterCount(10), isNot(contains(r'$remainingCount')));
|
||||
expect(
|
||||
localizations.remainingTextFieldCharacterCount(0),
|
||||
isNot(contains(r'$remainingCount')),
|
||||
);
|
||||
expect(
|
||||
localizations.remainingTextFieldCharacterCount(1),
|
||||
isNot(contains(r'$remainingCount')),
|
||||
);
|
||||
expect(
|
||||
localizations.remainingTextFieldCharacterCount(10),
|
||||
isNot(contains(r'$remainingCount')),
|
||||
);
|
||||
|
||||
expect(localizations.aboutListTileTitle('FOO'), isNotNull);
|
||||
expect(localizations.aboutListTileTitle('FOO'), contains('FOO'));
|
||||
@@ -125,13 +136,17 @@ void main() {
|
||||
testWidgets('translations spot check expansionTileExpandedHint', (WidgetTester tester) async {
|
||||
const Locale locale = Locale.fromSubtags(languageCode: 'en');
|
||||
expect(GlobalMaterialLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(locale);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<MaterialLocalizationEn>());
|
||||
expect(localizations.expansionTileExpandedHint, 'double tap to collapse');
|
||||
});
|
||||
|
||||
testWidgets('spot check selectedRowCount translations', (WidgetTester tester) async {
|
||||
MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('en'));
|
||||
MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(
|
||||
const Locale('en'),
|
||||
);
|
||||
expect(localizations.selectedRowCountTitle(0), 'No items selected');
|
||||
expect(localizations.selectedRowCountTitle(1), '1 item selected');
|
||||
expect(localizations.selectedRowCountTitle(2), '2 items selected');
|
||||
@@ -178,8 +193,12 @@ void main() {
|
||||
expect(localizations.selectedRowCountTitle(123456789), 'បានជ្រើសរើសធាតុ 123,456,789');
|
||||
});
|
||||
|
||||
testWidgets('spot check formatMediumDate(), formatFullDate() translations', (WidgetTester tester) async {
|
||||
MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('en'));
|
||||
testWidgets('spot check formatMediumDate(), formatFullDate() translations', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(
|
||||
const Locale('en'),
|
||||
);
|
||||
expect(localizations.formatMediumDate(DateTime(2015, 7, 23)), 'Thu, Jul 23');
|
||||
expect(localizations.formatFullDate(DateTime(2015, 7, 23)), 'Thursday, July 23, 2015');
|
||||
|
||||
@@ -506,13 +525,10 @@ void main() {
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/36704.
|
||||
testWidgets('kn arb file should be properly Unicode escaped', (WidgetTester tester) async {
|
||||
final File file = File(
|
||||
path.join(rootDirectoryPath, 'lib', 'src', 'l10n', 'material_kn.arb'),
|
||||
);
|
||||
final File file = File(path.join(rootDirectoryPath, 'lib', 'src', 'l10n', 'material_kn.arb'));
|
||||
|
||||
final Map<String, dynamic> bundle = json.decode(
|
||||
file.readAsStringSync(),
|
||||
) as Map<String, dynamic>;
|
||||
final Map<String, dynamic> bundle =
|
||||
json.decode(file.readAsStringSync()) as Map<String, dynamic>;
|
||||
|
||||
// Encodes the arb resource values if they have not already been
|
||||
// encoded.
|
||||
@@ -537,7 +553,9 @@ void main() {
|
||||
testWidgets('Finnish translation for tab label', (WidgetTester tester) async {
|
||||
const Locale locale = Locale('fi');
|
||||
expect(GlobalMaterialLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(locale);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<MaterialLocalizationFi>());
|
||||
expect(localizations.tabLabel(tabIndex: 1, tabCount: 2), 'Välilehti 1 kautta 2');
|
||||
});
|
||||
@@ -546,7 +564,9 @@ void main() {
|
||||
testWidgets('Share button label on Material', (WidgetTester tester) async {
|
||||
const Locale locale = Locale('en');
|
||||
expect(GlobalMaterialLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(locale);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<MaterialLocalizationEn>());
|
||||
expect(localizations.shareButtonLabel, 'Share');
|
||||
});
|
||||
@@ -555,16 +575,22 @@ void main() {
|
||||
testWidgets('zh-CN translation for look up label', (WidgetTester tester) async {
|
||||
const Locale locale = Locale('zh');
|
||||
expect(GlobalCupertinoLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(locale);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<MaterialLocalizationZh>());
|
||||
expect(localizations.lookUpButtonLabel, '查询');
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/pull/151364
|
||||
testWidgets('ko-KR translation for cut, copy, paste label in ButtonLabel', (WidgetTester tester) async {
|
||||
testWidgets('ko-KR translation for cut, copy, paste label in ButtonLabel', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
const Locale locale = Locale('ko');
|
||||
expect(GlobalCupertinoLocalizations.delegate.isSupported(locale), isTrue);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(locale);
|
||||
final MaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
expect(localizations, isA<MaterialLocalizationKo>());
|
||||
expect(localizations.cutButtonLabel, '잘라내기');
|
||||
expect(localizations.copyButtonLabel, '복사');
|
||||
|
||||
@@ -9,21 +9,19 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
|
||||
class FooMaterialLocalizations extends MaterialLocalizationEn {
|
||||
FooMaterialLocalizations(
|
||||
Locale localeName,
|
||||
this.backButtonTooltip,
|
||||
) : super(
|
||||
localeName: localeName.toString(),
|
||||
fullYearFormat: intl.DateFormat.y(),
|
||||
compactDateFormat: intl.DateFormat.yMd(),
|
||||
shortDateFormat: intl.DateFormat.yMMMd(),
|
||||
mediumDateFormat: intl.DateFormat('E, MMM\u00a0d'),
|
||||
longDateFormat: intl.DateFormat.yMMMMEEEEd(),
|
||||
yearMonthFormat: intl.DateFormat.yMMMM(),
|
||||
shortMonthDayFormat: intl.DateFormat.MMMd(),
|
||||
decimalFormat: intl.NumberFormat.decimalPattern(),
|
||||
twoDigitZeroPaddedFormat: intl.NumberFormat('00'),
|
||||
);
|
||||
FooMaterialLocalizations(Locale localeName, this.backButtonTooltip)
|
||||
: super(
|
||||
localeName: localeName.toString(),
|
||||
fullYearFormat: intl.DateFormat.y(),
|
||||
compactDateFormat: intl.DateFormat.yMd(),
|
||||
shortDateFormat: intl.DateFormat.yMMMd(),
|
||||
mediumDateFormat: intl.DateFormat('E, MMM\u00a0d'),
|
||||
longDateFormat: intl.DateFormat.yMMMMEEEEd(),
|
||||
yearMonthFormat: intl.DateFormat.yMMMM(),
|
||||
shortMonthDayFormat: intl.DateFormat.MMMd(),
|
||||
decimalFormat: intl.NumberFormat.decimalPattern(),
|
||||
twoDigitZeroPaddedFormat: intl.NumberFormat('00'),
|
||||
);
|
||||
|
||||
@override
|
||||
final String backButtonTooltip;
|
||||
@@ -45,7 +43,9 @@ class FooMaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLoc
|
||||
|
||||
@override
|
||||
Future<FooMaterialLocalizations> load(Locale locale) {
|
||||
return SynchronousFuture<FooMaterialLocalizations>(FooMaterialLocalizations(locale, backButtonTooltip));
|
||||
return SynchronousFuture<FooMaterialLocalizations>(
|
||||
FooMaterialLocalizations(locale, backButtonTooltip),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -57,10 +57,7 @@ Widget buildFrame({
|
||||
Iterable<LocalizationsDelegate<dynamic>> delegates = GlobalMaterialLocalizations.delegates,
|
||||
required WidgetBuilder buildContent,
|
||||
LocaleResolutionCallback? localeResolutionCallback,
|
||||
Iterable<Locale> supportedLocales = const <Locale>[
|
||||
Locale('en', 'US'),
|
||||
Locale('es', 'ES'),
|
||||
],
|
||||
Iterable<Locale> supportedLocales = const <Locale>[Locale('en', 'US'), Locale('es', 'ES')],
|
||||
}) {
|
||||
return MaterialApp(
|
||||
color: const Color(0xFFFFFFFF),
|
||||
@@ -72,7 +69,7 @@ Widget buildFrame({
|
||||
return MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return buildContent(context);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -85,12 +82,9 @@ void main() {
|
||||
await tester.pumpWidget(
|
||||
buildFrame(
|
||||
buildContent: (BuildContext context) {
|
||||
return Text(
|
||||
MaterialLocalizations.of(context).backButtonTooltip,
|
||||
key: textKey,
|
||||
);
|
||||
}
|
||||
)
|
||||
return Text(MaterialLocalizations.of(context).backButtonTooltip, key: textKey);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.widget<Text>(find.byKey(textKey)).data, 'Back');
|
||||
@@ -170,7 +164,9 @@ void main() {
|
||||
expect(find.text('Back'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('MaterialApp adds MaterialLocalizations for additional languages', (WidgetTester tester) async {
|
||||
testWidgets('MaterialApp adds MaterialLocalizations for additional languages', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final Key textKey = UniqueKey();
|
||||
|
||||
await tester.pumpWidget(
|
||||
@@ -180,18 +176,11 @@ void main() {
|
||||
const FooMaterialLocalizationsDelegate(supportedLanguage: 'de', backButtonTooltip: 'DE'),
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const <Locale>[
|
||||
Locale('en'),
|
||||
Locale('fr'),
|
||||
Locale('de'),
|
||||
],
|
||||
supportedLocales: const <Locale>[Locale('en'), Locale('fr'), Locale('de')],
|
||||
buildContent: (BuildContext context) {
|
||||
return Text(
|
||||
MaterialLocalizations.of(context).backButtonTooltip,
|
||||
key: textKey,
|
||||
);
|
||||
return Text(MaterialLocalizations.of(context).backButtonTooltip, key: textKey);
|
||||
},
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.widget<Text>(find.byKey(textKey)).data, 'Back');
|
||||
@@ -205,7 +194,9 @@ void main() {
|
||||
expect(find.text('DE'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('MaterialApp overrides MaterialLocalizations for all locales', (WidgetTester tester) async {
|
||||
testWidgets('MaterialApp overrides MaterialLocalizations for all locales', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final Key textKey = UniqueKey();
|
||||
|
||||
await tester.pumpWidget(
|
||||
@@ -218,12 +209,9 @@ void main() {
|
||||
],
|
||||
buildContent: (BuildContext context) {
|
||||
// Should always be 'foo', no matter what the locale is
|
||||
return Text(
|
||||
MaterialLocalizations.of(context).backButtonTooltip,
|
||||
key: textKey,
|
||||
);
|
||||
return Text(MaterialLocalizations.of(context).backButtonTooltip, key: textKey);
|
||||
},
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.widget<Text>(find.byKey(textKey)).data, 'foo');
|
||||
@@ -237,7 +225,9 @@ void main() {
|
||||
expect(find.text('foo'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('MaterialApp overrides MaterialLocalizations for default locale', (WidgetTester tester) async {
|
||||
testWidgets('MaterialApp overrides MaterialLocalizations for default locale', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final Key textKey = UniqueKey();
|
||||
|
||||
await tester.pumpWidget(
|
||||
@@ -248,12 +238,9 @@ void main() {
|
||||
],
|
||||
// supportedLocales not specified, so all locales resolve to 'en'
|
||||
buildContent: (BuildContext context) {
|
||||
return Text(
|
||||
MaterialLocalizations.of(context).backButtonTooltip,
|
||||
key: textKey,
|
||||
);
|
||||
return Text(MaterialLocalizations.of(context).backButtonTooltip, key: textKey);
|
||||
},
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
// Unsupported locale '_' (the widget tester's default) resolves to 'en'.
|
||||
@@ -282,12 +269,9 @@ void main() {
|
||||
const Locale('id', 'JV'),
|
||||
],
|
||||
buildContent: (BuildContext context) {
|
||||
return Text(
|
||||
'${Localizations.localeOf(context)}',
|
||||
key: textKey,
|
||||
);
|
||||
return Text('${Localizations.localeOf(context)}', key: textKey);
|
||||
},
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
expect(tester.widget<Text>(find.byKey(textKey)).data, 'en_US');
|
||||
@@ -300,7 +284,10 @@ void main() {
|
||||
// Yiddish was ji (ISO-639) is yi (ISO-639-1)
|
||||
await tester.binding.setLocale('ji', 'IL');
|
||||
await tester.pump();
|
||||
expect(tester.takeException(), "Warning: This application's locale, yi_IL, is not supported by all of its localization delegates.");
|
||||
expect(
|
||||
tester.takeException(),
|
||||
"Warning: This application's locale, yi_IL, is not supported by all of its localization delegates.",
|
||||
);
|
||||
expect(tester.widget<Text>(find.byKey(textKey)).data, 'yi_IL');
|
||||
|
||||
// Indonesian was in (ISO-639) is id (ISO-639-1)
|
||||
|
||||
@@ -13,10 +13,11 @@ void encodeBundleTranslations(Map<String, dynamic> bundle) {
|
||||
final String translation = bundle[key] as String;
|
||||
// Rewrite the string as a series of unicode characters in JSON format.
|
||||
// Like "\u0012\u0123\u1234".
|
||||
bundle[key] = translation.runes.map((int code) {
|
||||
final String codeString = '00${code.toRadixString(16)}';
|
||||
return '\\u${codeString.substring(codeString.length - 4)}';
|
||||
}).join();
|
||||
bundle[key] =
|
||||
translation.runes.map((int code) {
|
||||
final String codeString = '00${code.toRadixString(16)}';
|
||||
return '\\u${codeString.substring(codeString.length - 4)}';
|
||||
}).join();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,17 +43,11 @@ void main() {
|
||||
return <PopupMenuItem<int>>[
|
||||
const PopupMenuItem<int>(
|
||||
value: 1,
|
||||
child: Text(
|
||||
'hello, world',
|
||||
style: TextStyle(color: Colors.blue),
|
||||
),
|
||||
child: Text('hello, world', style: TextStyle(color: Colors.blue)),
|
||||
),
|
||||
const PopupMenuItem<int>(
|
||||
value: 2,
|
||||
child: Text(
|
||||
'你好,世界',
|
||||
style: TextStyle(color: Colors.blue),
|
||||
),
|
||||
child: Text('你好,世界', style: TextStyle(color: Colors.blue)),
|
||||
),
|
||||
];
|
||||
},
|
||||
@@ -114,17 +108,11 @@ void main() {
|
||||
return <PopupMenuItem<int>>[
|
||||
const PopupMenuItem<int>(
|
||||
value: 1,
|
||||
child: Text(
|
||||
'hello, world',
|
||||
style: TextStyle(color: Colors.blue),
|
||||
),
|
||||
child: Text('hello, world', style: TextStyle(color: Colors.blue)),
|
||||
),
|
||||
const PopupMenuItem<int>(
|
||||
value: 2,
|
||||
child: Text(
|
||||
'你好,世界',
|
||||
style: TextStyle(color: Colors.blue),
|
||||
),
|
||||
child: Text('你好,世界', style: TextStyle(color: Colors.blue)),
|
||||
),
|
||||
];
|
||||
},
|
||||
@@ -185,17 +173,11 @@ void main() {
|
||||
return <PopupMenuItem<int>>[
|
||||
const PopupMenuItem<int>(
|
||||
value: 1,
|
||||
child: Text(
|
||||
'hello, world',
|
||||
style: TextStyle(color: Colors.blue),
|
||||
),
|
||||
child: Text('hello, world', style: TextStyle(color: Colors.blue)),
|
||||
),
|
||||
const PopupMenuItem<int>(
|
||||
value: 2,
|
||||
child: Text(
|
||||
'你好,世界',
|
||||
style: TextStyle(color: Colors.blue),
|
||||
),
|
||||
child: Text('你好,世界', style: TextStyle(color: Colors.blue)),
|
||||
),
|
||||
];
|
||||
},
|
||||
@@ -256,17 +238,11 @@ void main() {
|
||||
return <PopupMenuItem<int>>[
|
||||
const PopupMenuItem<int>(
|
||||
value: 1,
|
||||
child: Text(
|
||||
'hello, world',
|
||||
style: TextStyle(color: Colors.blue),
|
||||
),
|
||||
child: Text('hello, world', style: TextStyle(color: Colors.blue)),
|
||||
),
|
||||
const PopupMenuItem<int>(
|
||||
value: 2,
|
||||
child: Text(
|
||||
'你好,世界',
|
||||
style: TextStyle(color: Colors.blue),
|
||||
),
|
||||
child: Text('你好,世界', style: TextStyle(color: Colors.blue)),
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
@@ -13,7 +13,9 @@ void main() {
|
||||
|
||||
expect(GlobalWidgetsLocalizations.delegate.isSupported(locale), isTrue);
|
||||
|
||||
final WidgetsLocalizations localizations = await GlobalWidgetsLocalizations.delegate.load(locale);
|
||||
final WidgetsLocalizations localizations = await GlobalWidgetsLocalizations.delegate.load(
|
||||
locale,
|
||||
);
|
||||
|
||||
expect(localizations.reorderItemDown, isNotNull);
|
||||
expect(localizations.reorderItemLeft, isNotNull);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user