diff --git a/packages/flutter_localizations/analysis_options.yaml b/packages/flutter_localizations/analysis_options.yaml new file mode 100644 index 0000000000..2344f5ab1f --- /dev/null +++ b/packages/flutter_localizations/analysis_options.yaml @@ -0,0 +1,12 @@ +# 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 diff --git a/packages/flutter_localizations/lib/src/utils/date_localizations.dart b/packages/flutter_localizations/lib/src/utils/date_localizations.dart index 79ffb38396..9b0abd856b 100644 --- a/packages/flutter_localizations/lib/src/utils/date_localizations.dart +++ b/packages/flutter_localizations/lib/src/utils/date_localizations.dart @@ -21,29 +21,31 @@ void loadDateIntlDataIfNotLoaded() { // This can only happen if a locale with a stripped scriptCode has already // been initialzed. This should be removed when scriptCode stripping is removed. final Set initializedLocales = {}; - date_localizations.dateSymbols.forEach((String locale, dynamic data) { - // Strip scriptCode from the locale, as we do not distinguish between scripts - // for dates. - final List codes = locale.split('_'); - String countryCode; - if (codes.length == 2) { - countryCode = codes[1].length < 4 ? codes[1] : null; - } else if (codes.length == 3) { - countryCode = codes[1].length < codes[2].length ? codes[1] : codes[2]; - } - locale = codes[0] + (countryCode != null ? '_' + countryCode : ''); - if (initializedLocales.contains(locale)) - return; - initializedLocales.add(locale); - // Perform initialization. - assert(date_localizations.datePatterns.containsKey(locale)); - final intl.DateSymbols symbols = intl.DateSymbols.deserializeFromMap(data); - date_symbol_data_custom.initializeDateFormattingCustom( - locale: locale, - symbols: symbols, - patterns: date_localizations.datePatterns[locale], - ); - }); + date_localizations.dateSymbols + .cast>() + .forEach((String locale, Map data) { + // Strip scriptCode from the locale, as we do not distinguish between scripts + // for dates. + final List codes = locale.split('_'); + String countryCode; + if (codes.length == 2) { + countryCode = codes[1].length < 4 ? codes[1] : null; + } else if (codes.length == 3) { + countryCode = codes[1].length < codes[2].length ? codes[1] : codes[2]; + } + locale = codes[0] + (countryCode != null ? '_' + countryCode : ''); + if (initializedLocales.contains(locale)) + return; + initializedLocales.add(locale); + // Perform initialization. + assert(date_localizations.datePatterns.containsKey(locale)); + final intl.DateSymbols symbols = intl.DateSymbols.deserializeFromMap(data); + date_symbol_data_custom.initializeDateFormattingCustom( + locale: locale, + symbols: symbols, + patterns: date_localizations.datePatterns[locale], + ); + }); _dateIntlDataInitialized = true; } } diff --git a/packages/flutter_localizations/test/material/date_picker_test.dart b/packages/flutter_localizations/test/material/date_picker_test.dart index 02ffb6f550..99d8074d39 100644 --- a/packages/flutter_localizations/test/material/date_picker_test.dart +++ b/packages/flutter_localizations/test/material/date_picker_test.dart @@ -53,10 +53,10 @@ void main() { for (Locale locale in testLocales.keys) { testWidgets('shows dates for $locale', (WidgetTester tester) async { - final List expectedDaysOfWeek = testLocales[locale]['expectedDaysOfWeek']; - final List expectedDaysOfMonth = testLocales[locale]['expectedDaysOfMonth']; - final String expectedMonthYearHeader = testLocales[locale]['expectedMonthYearHeader']; - final TextDirection textDirection = testLocales[locale]['textDirection']; + final List expectedDaysOfWeek = testLocales[locale]['expectedDaysOfWeek'] as List; + final List expectedDaysOfMonth = testLocales[locale]['expectedDaysOfMonth'] as List; + 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, DayPicker( diff --git a/packages/flutter_localizations/test/material/date_time_test.dart b/packages/flutter_localizations/test/material/date_time_test.dart index ea6162fd3e..0b7960630a 100644 --- a/packages/flutter_localizations/test/material/date_time_test.dart +++ b/packages/flutter_localizations/test/material/date_time_test.dart @@ -11,12 +11,14 @@ import 'package:flutter_test/flutter_test.dart'; void main() { group(GlobalMaterialLocalizations, () { 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'); }); 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'); }); @@ -67,7 +69,8 @@ void main() { group('formatMinute', () { 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'); }); }); diff --git a/packages/flutter_localizations/test/material/time_picker_test.dart b/packages/flutter_localizations/test/material/time_picker_test.dart index cfaca11a08..a4bbc7dcd8 100644 --- a/packages/flutter_localizations/test/material/time_picker_test.dart +++ b/packages/flutter_localizations/test/material/time_picker_test.dart @@ -72,7 +72,7 @@ void main() { final Offset center = await startPicker(tester, (TimeOfDay time) { }, locale: locale); final List actual = []; 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 dynamic widget = layout.child; if (fragmentType == '_MinuteControl') { @@ -174,12 +174,18 @@ void main() { final CustomPaint dialPaint = tester.widget(find.byKey(const ValueKey('time-picker-dial'))); final dynamic dialPainter = dialPaint.painter; - final List primaryOuterLabels = dialPainter.primaryOuterLabels; - expect(primaryOuterLabels.map((dynamic tp) => tp.painter.text.text), labels12To11); + final List primaryOuterLabels = dialPainter.primaryOuterLabels as List; + expect( + primaryOuterLabels.map((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text), + labels12To11, + ); expect(dialPainter.primaryInnerLabels, null); - final List secondaryOuterLabels = dialPainter.secondaryOuterLabels; - expect(secondaryOuterLabels.map((dynamic tp) => tp.painter.text.text), labels12To11); + final List secondaryOuterLabels = dialPainter.secondaryOuterLabels as List; + expect( + secondaryOuterLabels.map((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text), + labels12To11, + ); expect(dialPainter.secondaryInnerLabels, null); }); @@ -188,14 +194,26 @@ void main() { final CustomPaint dialPaint = tester.widget(find.byKey(const ValueKey('time-picker-dial'))); final dynamic dialPainter = dialPaint.painter; - final List primaryOuterLabels = dialPainter.primaryOuterLabels; - expect(primaryOuterLabels.map((dynamic tp) => tp.painter.text.text), labels00To23); - final List primaryInnerLabels = dialPainter.primaryInnerLabels; - expect(primaryInnerLabels.map((dynamic tp) => tp.painter.text.text), labels12To11TwoDigit); + final List primaryOuterLabels = dialPainter.primaryOuterLabels as List; + expect( + primaryOuterLabels.map((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text), + labels00To23, + ); + final List primaryInnerLabels = dialPainter.primaryInnerLabels as List; + expect( + primaryInnerLabels.map((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text), + labels12To11TwoDigit, + ); - final List secondaryOuterLabels = dialPainter.secondaryOuterLabels; - expect(secondaryOuterLabels.map((dynamic tp) => tp.painter.text.text), labels00To23); - final List secondaryInnerLabels = dialPainter.secondaryInnerLabels; - expect(secondaryInnerLabels.map((dynamic tp) => tp.painter.text.text), labels12To11TwoDigit); + final List secondaryOuterLabels = dialPainter.secondaryOuterLabels as List; + expect( + secondaryOuterLabels.map((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text), + labels00To23, + ); + final List secondaryInnerLabels = dialPainter.secondaryInnerLabels as List; + expect( + secondaryInnerLabels.map((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text), + labels12To11TwoDigit, + ); }); }