l10n.yaml's nullable-getter option should default to true (#124353)
Currently, nullable-getter defaults to false when l10n.yaml is not present, which is not the same behavior as when an l10n.yaml file is present and nullable-getter is not set. Fixes #120457.
This commit is contained in:
parent
9b530298fa
commit
b6c7df447d
@ -179,6 +179,7 @@ class GenerateLocalizationsCommand extends FlutterCommand {
|
||||
);
|
||||
argParser.addFlag(
|
||||
'nullable-getter',
|
||||
defaultsTo: true,
|
||||
help: 'Whether or not the localizations class getter is nullable.\n'
|
||||
'\n'
|
||||
'By default, this value is set to true so that '
|
||||
|
@ -319,4 +319,36 @@ untranslated-messages-file: lib/l10n/untranslated.json
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
|
||||
testUsingContext('nullable-getter defaults to true', () async {
|
||||
final File arbFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_en.arb'))
|
||||
..createSync(recursive: true);
|
||||
arbFile.writeAsStringSync('''
|
||||
{
|
||||
"helloWorld": "Hello, World!",
|
||||
"@helloWorld": {
|
||||
"description": "Sample description"
|
||||
}
|
||||
}''');
|
||||
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
|
||||
pubspecFile.writeAsStringSync(BasicProjectWithFlutterGen().pubspec);
|
||||
final GenerateLocalizationsCommand command = GenerateLocalizationsCommand(
|
||||
fileSystem: fileSystem,
|
||||
logger: logger,
|
||||
artifacts: artifacts,
|
||||
processManager: processManager,
|
||||
);
|
||||
await createTestCommandRunner(command).run(<String>['gen-l10n']);
|
||||
|
||||
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'));
|
||||
expect(outputDirectory.existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), isTrue);
|
||||
expect(
|
||||
outputDirectory.childFile('app_localizations.dart').readAsStringSync(),
|
||||
contains('static AppLocalizations? of(BuildContext context)'),
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => FakeProcessManager.any(),
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user