Unverified Commit 36e599eb authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

implicit-casts:false in flutter_localizations (#45241)

parent 01953a10
# Override the parent analysis_options until all the repo has implicit-casts: false
include: ../analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
linter:
rules:
avoid_as: false
...@@ -21,29 +21,31 @@ void loadDateIntlDataIfNotLoaded() { ...@@ -21,29 +21,31 @@ void loadDateIntlDataIfNotLoaded() {
// This can only happen if a locale with a stripped scriptCode has already // This can only happen if a locale with a stripped scriptCode has already
// been initialzed. This should be removed when scriptCode stripping is removed. // been initialzed. This should be removed when scriptCode stripping is removed.
final Set<String> initializedLocales = <String>{}; final Set<String> initializedLocales = <String>{};
date_localizations.dateSymbols.forEach((String locale, dynamic data) { date_localizations.dateSymbols
// Strip scriptCode from the locale, as we do not distinguish between scripts .cast<String, Map<String, dynamic>>()
// for dates. .forEach((String locale, Map<String, dynamic> data) {
final List<String> codes = locale.split('_'); // Strip scriptCode from the locale, as we do not distinguish between scripts
String countryCode; // for dates.
if (codes.length == 2) { final List<String> codes = locale.split('_');
countryCode = codes[1].length < 4 ? codes[1] : null; String countryCode;
} else if (codes.length == 3) { if (codes.length == 2) {
countryCode = codes[1].length < codes[2].length ? codes[1] : codes[2]; countryCode = codes[1].length < 4 ? codes[1] : null;
} } else if (codes.length == 3) {
locale = codes[0] + (countryCode != null ? '_' + countryCode : ''); countryCode = codes[1].length < codes[2].length ? codes[1] : codes[2];
if (initializedLocales.contains(locale)) }
return; locale = codes[0] + (countryCode != null ? '_' + countryCode : '');
initializedLocales.add(locale); if (initializedLocales.contains(locale))
// Perform initialization. return;
assert(date_localizations.datePatterns.containsKey(locale)); initializedLocales.add(locale);
final intl.DateSymbols symbols = intl.DateSymbols.deserializeFromMap(data); // Perform initialization.
date_symbol_data_custom.initializeDateFormattingCustom( assert(date_localizations.datePatterns.containsKey(locale));
locale: locale, final intl.DateSymbols symbols = intl.DateSymbols.deserializeFromMap(data);
symbols: symbols, date_symbol_data_custom.initializeDateFormattingCustom(
patterns: date_localizations.datePatterns[locale], locale: locale,
); symbols: symbols,
}); patterns: date_localizations.datePatterns[locale],
);
});
_dateIntlDataInitialized = true; _dateIntlDataInitialized = true;
} }
} }
...@@ -53,10 +53,10 @@ void main() { ...@@ -53,10 +53,10 @@ void main() {
for (Locale locale in testLocales.keys) { for (Locale locale in testLocales.keys) {
testWidgets('shows dates for $locale', (WidgetTester tester) async { testWidgets('shows dates for $locale', (WidgetTester tester) async {
final List<String> expectedDaysOfWeek = testLocales[locale]['expectedDaysOfWeek']; final List<String> expectedDaysOfWeek = testLocales[locale]['expectedDaysOfWeek'] as List<String>;
final List<String> expectedDaysOfMonth = testLocales[locale]['expectedDaysOfMonth']; final List<String> expectedDaysOfMonth = testLocales[locale]['expectedDaysOfMonth'] as List<String>;
final String expectedMonthYearHeader = testLocales[locale]['expectedMonthYearHeader']; final String expectedMonthYearHeader = testLocales[locale]['expectedMonthYearHeader'] as String;
final TextDirection textDirection = testLocales[locale]['textDirection']; final TextDirection textDirection = testLocales[locale]['textDirection'] as TextDirection;
final DateTime baseDate = DateTime(2017, 9, 27); final DateTime baseDate = DateTime(2017, 9, 27);
await _pumpBoilerplate(tester, DayPicker( await _pumpBoilerplate(tester, DayPicker(
......
...@@ -11,12 +11,14 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -11,12 +11,14 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
group(GlobalMaterialLocalizations, () { group(GlobalMaterialLocalizations, () {
test('uses exact locale when exists', () async { test('uses exact locale when exists', () async {
final GlobalMaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('pt', 'PT')); final GlobalMaterialLocalizations localizations =
await GlobalMaterialLocalizations.delegate.load(const Locale('pt', 'PT')) as GlobalMaterialLocalizations;
expect(localizations.formatDecimal(10000), '10\u00A0000'); expect(localizations.formatDecimal(10000), '10\u00A0000');
}); });
test('falls back to language code when exact locale is missing', () async { test('falls back to language code when exact locale is missing', () async {
final GlobalMaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('pt', 'XX')); final GlobalMaterialLocalizations localizations =
await GlobalMaterialLocalizations.delegate.load(const Locale('pt', 'XX')) as GlobalMaterialLocalizations;
expect(localizations.formatDecimal(10000), '10.000'); expect(localizations.formatDecimal(10000), '10.000');
}); });
...@@ -67,7 +69,8 @@ void main() { ...@@ -67,7 +69,8 @@ void main() {
group('formatMinute', () { group('formatMinute', () {
test('formats English', () async { test('formats English', () async {
final GlobalMaterialLocalizations localizations = await GlobalMaterialLocalizations.delegate.load(const Locale('en', 'US')); final GlobalMaterialLocalizations localizations =
await GlobalMaterialLocalizations.delegate.load(const Locale('en', 'US')) as GlobalMaterialLocalizations;
expect(localizations.formatMinute(const TimeOfDay(hour: 1, minute: 32)), '32'); expect(localizations.formatMinute(const TimeOfDay(hour: 1, minute: 32)), '32');
}); });
}); });
......
...@@ -72,7 +72,7 @@ void main() { ...@@ -72,7 +72,7 @@ void main() {
final Offset center = await startPicker(tester, (TimeOfDay time) { }, locale: locale); final Offset center = await startPicker(tester, (TimeOfDay time) { }, locale: locale);
final List<String> actual = <String>[]; final List<String> actual = <String>[];
tester.element(find.byType(CustomMultiChildLayout)).visitChildren((Element child) { tester.element(find.byType(CustomMultiChildLayout)).visitChildren((Element child) {
final LayoutId layout = child.widget; final LayoutId layout = child.widget as LayoutId;
final String fragmentType = '${layout.child.runtimeType}'; final String fragmentType = '${layout.child.runtimeType}';
final dynamic widget = layout.child; final dynamic widget = layout.child;
if (fragmentType == '_MinuteControl') { if (fragmentType == '_MinuteControl') {
...@@ -174,12 +174,18 @@ void main() { ...@@ -174,12 +174,18 @@ void main() {
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; final dynamic dialPainter = dialPaint.painter;
final List<dynamic> primaryOuterLabels = dialPainter.primaryOuterLabels; final List<dynamic> primaryOuterLabels = dialPainter.primaryOuterLabels as List<dynamic>;
expect(primaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11); expect(
primaryOuterLabels.map<String>((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text),
labels12To11,
);
expect(dialPainter.primaryInnerLabels, null); expect(dialPainter.primaryInnerLabels, null);
final List<dynamic> secondaryOuterLabels = dialPainter.secondaryOuterLabels; final List<dynamic> secondaryOuterLabels = dialPainter.secondaryOuterLabels as List<dynamic>;
expect(secondaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11); expect(
secondaryOuterLabels.map<String>((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text),
labels12To11,
);
expect(dialPainter.secondaryInnerLabels, null); expect(dialPainter.secondaryInnerLabels, null);
}); });
...@@ -188,14 +194,26 @@ void main() { ...@@ -188,14 +194,26 @@ void main() {
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; final dynamic dialPainter = dialPaint.painter;
final List<dynamic> primaryOuterLabels = dialPainter.primaryOuterLabels; final List<dynamic> primaryOuterLabels = dialPainter.primaryOuterLabels as List<dynamic>;
expect(primaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels00To23); expect(
final List<dynamic> primaryInnerLabels = dialPainter.primaryInnerLabels; primaryOuterLabels.map<String>((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text),
expect(primaryInnerLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11TwoDigit); labels00To23,
);
final List<dynamic> secondaryOuterLabels = dialPainter.secondaryOuterLabels; final List<dynamic> primaryInnerLabels = dialPainter.primaryInnerLabels as List<dynamic>;
expect(secondaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels00To23); expect(
final List<dynamic> secondaryInnerLabels = dialPainter.secondaryInnerLabels; primaryInnerLabels.map<String>((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text),
expect(secondaryInnerLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11TwoDigit); labels12To11TwoDigit,
);
final List<dynamic> secondaryOuterLabels = dialPainter.secondaryOuterLabels as List<dynamic>;
expect(
secondaryOuterLabels.map<String>((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text),
labels00To23,
);
final List<dynamic> secondaryInnerLabels = dialPainter.secondaryInnerLabels as List<dynamic>;
expect(
secondaryInnerLabels.map<String>((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text),
labels12To11TwoDigit,
);
}); });
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment