diff --git a/packages/flutter_tools/lib/src/localizations/gen_l10n_types.dart b/packages/flutter_tools/lib/src/localizations/gen_l10n_types.dart index 1d289f25b9..7ffc2bf628 100644 --- a/packages/flutter_tools/lib/src/localizations/gen_l10n_types.dart +++ b/packages/flutter_tools/lib/src/localizations/gen_l10n_types.dart @@ -2,15 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:intl/locale.dart'; import '../base/file_system.dart'; import '../convert.dart'; -import '../globals.dart' as globals; - - import 'localizations_utils.dart'; // The set of date formats that can be automatically localized. @@ -202,9 +197,9 @@ class Placeholder { final String resourceId; final String name; - final String example; - final String type; - final String format; + final String? example; + final String? type; + final String? format; final List optionalParameters; bool get requiresFormatting => ['DateTime', 'double', 'int', 'num'].contains(type); @@ -214,7 +209,7 @@ class Placeholder { bool get isDate => 'DateTime' == type; bool get hasValidDateFormat => _validDateFormats.contains(format); - static String _stringAttribute( + static String? _stringAttribute( String resourceId, String name, Map attributes, @@ -224,13 +219,13 @@ class Placeholder { if (value == null) { return null; } - if (value is! String || (value as String).isEmpty) { + if (value is! String || value.isEmpty) { throw L10nException( 'The "$attributeName" value of the "$name" placeholder in message $resourceId ' 'must be a non-empty string.', ); } - return value as String; + return value; } static List _optionalParameters( @@ -249,9 +244,9 @@ class Placeholder { 'with keys that are strings.' ); } - final Map optionalParameterMap = value as Map; + final Map optionalParameterMap = value; return optionalParameterMap.keys.map((String parameterName) { - return OptionalParameter(parameterName, optionalParameterMap[parameterName]); + return OptionalParameter(parameterName, optionalParameterMap[parameterName]!); }).toList(); } } @@ -284,17 +279,17 @@ class Message { final String resourceId; final String value; - final String description; + final String? description; final List placeholders; - final RegExpMatch _pluralMatch; + final RegExpMatch? _pluralMatch; - bool get isPlural => _pluralMatch != null && _pluralMatch.groupCount == 1; + bool get isPlural => _pluralMatch != null && _pluralMatch!.groupCount == 1; bool get placeholdersRequireFormatting => placeholders.any((Placeholder p) => p.requiresFormatting); Placeholder getCountPlaceholder() { assert(isPlural); - final String countPlaceholderName = _pluralMatch[1]; + final String countPlaceholderName = _pluralMatch![1]!; return placeholders.firstWhere( (Placeholder p) => p.name == countPlaceholderName, orElse: () { @@ -336,7 +331,7 @@ class Message { ); } - final RegExpMatch pluralRegExp = _pluralRE.firstMatch(_value(bundle, resourceId)); + final RegExpMatch? pluralRegExp = _pluralRE.firstMatch(_value(bundle, resourceId)); final bool isPlural = pluralRegExp != null && pluralRegExp.groupCount == 1; if (attributes == null && isPlural) { throw L10nException( @@ -348,7 +343,7 @@ class Message { return attributes as Map; } - static String _description( + static String? _description( Map bundle, String resourceId, bool isResourceAttributeRequired, @@ -367,7 +362,7 @@ class Message { 'The description for "@$resourceId" is not a properly formatted String.' ); } - return value as String; + return value; } static List _placeholders( @@ -379,17 +374,16 @@ class Message { if (resourceAttributes == null) { return []; } - final dynamic value = resourceAttributes['placeholders']; - if (value == null) { + final dynamic allPlaceholdersMap = resourceAttributes['placeholders']; + if (allPlaceholdersMap == null) { return []; } - if (value is! Map) { + if (allPlaceholdersMap is! Map) { throw L10nException( 'The "placeholders" attribute for message $resourceId, is not ' 'properly formatted. Ensure that it is a map with string valued keys.' ); } - final Map allPlaceholdersMap = value as Map; return allPlaceholdersMap.keys.map((String placeholderName) { final dynamic value = allPlaceholdersMap[placeholderName]; if (value is! Map) { @@ -399,7 +393,7 @@ class Message { 'with string valued keys.' ); } - return Placeholder(resourceId, placeholderName, value as Map); + return Placeholder(resourceId, placeholderName, value); }).toList(); } } @@ -422,13 +416,13 @@ class AppResourceBundle { String localeString = resources['@@locale'] as String; // Look for the first instance of an ISO 639-1 language code, matching exactly. - final String fileName = globals.fs.path.basenameWithoutExtension(file.path); + final String fileName = file.fileSystem.path.basenameWithoutExtension(file.path); for (int index = 0; index < fileName.length; index += 1) { // If an underscore was found, check if locale string follows. if (fileName[index] == '_' && fileName[index + 1] != null) { // If Locale.tryParse fails, it returns null. - final Locale parserResult = Locale.tryParse(fileName.substring(index + 1)); + final Locale? parserResult = Locale.tryParse(fileName.substring(index + 1)); // If the parserResult is not an actual locale identifier, end the loop. if (parserResult != null && _iso639Languages.contains(parserResult.languageCode)) { // The parsed result uses dashes ('-'), but we want underscores ('_'). @@ -508,7 +502,7 @@ class AppResourceBundleCollection { } localeToBundle[bundle.locale] = bundle; languageToLocales[bundle.locale.languageCode] ??= []; - languageToLocales[bundle.locale.languageCode].add(bundle.locale); + languageToLocales[bundle.locale.languageCode]!.add(bundle.locale); } } @@ -539,7 +533,7 @@ class AppResourceBundleCollection { Iterable get locales => _localeToBundle.keys; Iterable get bundles => _localeToBundle.values; - AppResourceBundle bundleFor(LocaleInfo locale) => _localeToBundle[locale]; + AppResourceBundle? bundleFor(LocaleInfo locale) => _localeToBundle[locale]; Iterable get languages => _languageToLocales.keys; Iterable localesForLanguage(String language) => _languageToLocales[language] ?? [];