Unverified Commit b6c7df44 authored by Tae Hyung Kim's avatar Tae Hyung Kim Committed by GitHub

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.
parent 9b530298
......@@ -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(),
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment