implicit-casts:false in flutter_localizations (#45241)
This commit is contained in:
committed by
GitHub
parent
01953a1015
commit
36e599eb5d
12
packages/flutter_localizations/analysis_options.yaml
Normal file
12
packages/flutter_localizations/analysis_options.yaml
Normal file
@@ -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
|
||||
@@ -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<String> initializedLocales = <String>{};
|
||||
date_localizations.dateSymbols.forEach((String locale, dynamic data) {
|
||||
// Strip scriptCode from the locale, as we do not distinguish between scripts
|
||||
// for dates.
|
||||
final List<String> 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<String, Map<String, dynamic>>()
|
||||
.forEach((String locale, Map<String, dynamic> data) {
|
||||
// Strip scriptCode from the locale, as we do not distinguish between scripts
|
||||
// for dates.
|
||||
final List<String> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ void main() {
|
||||
|
||||
for (Locale locale in testLocales.keys) {
|
||||
testWidgets('shows dates for $locale', (WidgetTester tester) async {
|
||||
final List<String> expectedDaysOfWeek = testLocales[locale]['expectedDaysOfWeek'];
|
||||
final List<String> expectedDaysOfMonth = testLocales[locale]['expectedDaysOfMonth'];
|
||||
final String expectedMonthYearHeader = testLocales[locale]['expectedMonthYearHeader'];
|
||||
final TextDirection textDirection = testLocales[locale]['textDirection'];
|
||||
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, DayPicker(
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,7 +72,7 @@ void main() {
|
||||
final Offset center = await startPicker(tester, (TimeOfDay time) { }, locale: locale);
|
||||
final List<String> actual = <String>[];
|
||||
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<String>('time-picker-dial')));
|
||||
final dynamic dialPainter = dialPaint.painter;
|
||||
final List<dynamic> primaryOuterLabels = dialPainter.primaryOuterLabels;
|
||||
expect(primaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11);
|
||||
final List<dynamic> primaryOuterLabels = dialPainter.primaryOuterLabels as List<dynamic>;
|
||||
expect(
|
||||
primaryOuterLabels.map<String>((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text),
|
||||
labels12To11,
|
||||
);
|
||||
expect(dialPainter.primaryInnerLabels, null);
|
||||
|
||||
final List<dynamic> secondaryOuterLabels = dialPainter.secondaryOuterLabels;
|
||||
expect(secondaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11);
|
||||
final List<dynamic> secondaryOuterLabels = dialPainter.secondaryOuterLabels as List<dynamic>;
|
||||
expect(
|
||||
secondaryOuterLabels.map<String>((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<String>('time-picker-dial')));
|
||||
final dynamic dialPainter = dialPaint.painter;
|
||||
final List<dynamic> primaryOuterLabels = dialPainter.primaryOuterLabels;
|
||||
expect(primaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels00To23);
|
||||
final List<dynamic> primaryInnerLabels = dialPainter.primaryInnerLabels;
|
||||
expect(primaryInnerLabels.map<String>((dynamic tp) => tp.painter.text.text), labels12To11TwoDigit);
|
||||
final List<dynamic> primaryOuterLabels = dialPainter.primaryOuterLabels as List<dynamic>;
|
||||
expect(
|
||||
primaryOuterLabels.map<String>((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text),
|
||||
labels00To23,
|
||||
);
|
||||
final List<dynamic> primaryInnerLabels = dialPainter.primaryInnerLabels as List<dynamic>;
|
||||
expect(
|
||||
primaryInnerLabels.map<String>((dynamic tp) => ((tp.painter as TextPainter).text as TextSpan).text),
|
||||
labels12To11TwoDigit,
|
||||
);
|
||||
|
||||
final List<dynamic> secondaryOuterLabels = dialPainter.secondaryOuterLabels;
|
||||
expect(secondaryOuterLabels.map<String>((dynamic tp) => tp.painter.text.text), labels00To23);
|
||||
final List<dynamic> secondaryInnerLabels = dialPainter.secondaryInnerLabels;
|
||||
expect(secondaryInnerLabels.map<String>((dynamic tp) => tp.painter.text.text), 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,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user