diff --git a/engine/src/flutter/tools/gen_locale.dart b/engine/src/flutter/tools/gen_locale.dart index 2c4cedcea0..a154a8f2d9 100644 --- a/engine/src/flutter/tools/gen_locale.dart +++ b/engine/src/flutter/tools/gen_locale.dart @@ -2,9 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// TODO(goderbauer): Migrate this to null safety, https://github.com/flutter/flutter/issues/108933 -// @dart = 2.7 - // This file is used to generate the switch statements in the Locale class. // See: ../lib/ui/window.dart @@ -14,6 +11,8 @@ // this script (the first set for _canonicalizeLanguageCode and the second set // for _canonicalizeRegionCode). +// ignore_for_file: avoid_print + import 'dart:async'; import 'dart:convert'; import 'dart:io'; @@ -22,7 +21,7 @@ const String registry = 'https://www.iana.org/assignments/language-subtag-regist Map> parseSection(String section) { final Map> result = >{}; - List lastHeading; + late List lastHeading; for (final String line in section.split('\n')) { if (line == '') { continue; @@ -37,8 +36,7 @@ Map> parseSection(String section) { } final String name = line.substring(0, colon); final String value = line.substring(colon + 2); - lastHeading = result.putIfAbsent(name, () => []); - result[name].add(value); + lastHeading = result.putIfAbsent(name, () => [])..add(value); } return result; } @@ -48,29 +46,29 @@ Future main() async { final String body = (await (await (await client.getUrl(Uri.parse(registry))).close()).transform(utf8.decoder).toList()).join(); final List>> sections = body.split('%%').map>>(parseSection).toList(); final Map> outputs = >{'language': [], 'region': []}; - String fileDate; + String? fileDate; for (final Map> section in sections) { if (fileDate == null) { // first block should contain a File-Date metadata line. - fileDate = section['File-Date'].single; + fileDate = section['File-Date']!.single; continue; } assert(section.containsKey('Type'), section.toString()); - final String type = section['Type'].single; + final String type = section['Type']!.single; if ((type == 'language' || type == 'region') && (section.containsKey('Preferred-Value'))) { assert(section.containsKey('Subtag'), section.toString()); - final String subtag = section['Subtag'].single; - final List descriptions = section['Description']; + final String subtag = section['Subtag']!.single; + final List descriptions = section['Description']!; assert(descriptions.isNotEmpty); assert(section.containsKey('Deprecated')); - final String comment = section.containsKey('Comment') ? section['Comment'].single : 'deprecated ${section['Deprecated'].single}'; - final String preferredValue = section['Preferred-Value'].single; - outputs[type].add("'$subtag': '$preferredValue', // ${descriptions.join(", ")}; $comment"); + final String comment = section.containsKey('Comment') ? section['Comment']!.single : 'deprecated ${section['Deprecated']!.single}'; + final String preferredValue = section['Preferred-Value']!.single; + outputs[type]!.add("'$subtag': '$preferredValue', // ${descriptions.join(", ")}; $comment"); } } print('// Mappings generated for language subtag registry as of $fileDate.'); print('// For languageCode:'); - print(outputs['language'].join('\n')); + print(outputs['language']!.join('\n')); print('// For regionCode:'); - print(outputs['region'].join('\n')); + print(outputs['region']!.join('\n')); }