Skip to content

Commit b6c7df4

Browse files
authored
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.
1 parent 9b53029 commit b6c7df4

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

packages/flutter_tools/lib/src/commands/generate_localizations.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class GenerateLocalizationsCommand extends FlutterCommand {
179179
);
180180
argParser.addFlag(
181181
'nullable-getter',
182+
defaultsTo: true,
182183
help: 'Whether or not the localizations class getter is nullable.\n'
183184
'\n'
184185
'By default, this value is set to true so that '

packages/flutter_tools/test/commands.shard/hermetic/generate_localizations_test.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,36 @@ untranslated-messages-file: lib/l10n/untranslated.json
319319
FileSystem: () => fileSystem,
320320
ProcessManager: () => FakeProcessManager.any(),
321321
});
322+
323+
testUsingContext('nullable-getter defaults to true', () async {
324+
final File arbFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_en.arb'))
325+
..createSync(recursive: true);
326+
arbFile.writeAsStringSync('''
327+
{
328+
"helloWorld": "Hello, World!",
329+
"@helloWorld": {
330+
"description": "Sample description"
331+
}
332+
}''');
333+
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
334+
pubspecFile.writeAsStringSync(BasicProjectWithFlutterGen().pubspec);
335+
final GenerateLocalizationsCommand command = GenerateLocalizationsCommand(
336+
fileSystem: fileSystem,
337+
logger: logger,
338+
artifacts: artifacts,
339+
processManager: processManager,
340+
);
341+
await createTestCommandRunner(command).run(<String>['gen-l10n']);
342+
343+
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'));
344+
expect(outputDirectory.existsSync(), isTrue);
345+
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), isTrue);
346+
expect(
347+
outputDirectory.childFile('app_localizations.dart').readAsStringSync(),
348+
contains('static AppLocalizations? of(BuildContext context)'),
349+
);
350+
}, overrides: <Type, Generator>{
351+
FileSystem: () => fileSystem,
352+
ProcessManager: () => FakeProcessManager.any(),
353+
});
322354
}

0 commit comments

Comments
 (0)