diff --git a/packages/flutter_tools/lib/src/build_system/targets/localizations.dart b/packages/flutter_tools/lib/src/build_system/targets/localizations.dart index af0f007792..5b5e751646 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/localizations.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/localizations.dart @@ -61,9 +61,9 @@ class GenerateLocalizationsTarget extends Target { fileSystem: environment.fileSystem, ); - final Map dependencies = json.decode( + final Map dependencies = json.decode( environment.buildDir.childFile(_kDependenciesFileName).readAsStringSync() - ) as Map; + ) as Map; final List? inputs = dependencies['inputs'] as List?; final List? outputs = dependencies['outputs'] as List?; final Depfile depfile = Depfile( diff --git a/packages/flutter_tools/test/commands.shard/hermetic/pub_get_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/pub_get_test.dart index 61a4010a47..080fa54e79 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/pub_get_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/pub_get_test.dart @@ -10,6 +10,7 @@ import 'package:flutter_tools/src/commands/packages.dart'; import 'package:flutter_tools/src/dart/pub.dart'; import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/reporting/reporting.dart'; +import 'package:flutter_tools/src/runner/flutter_command.dart'; import 'package:test/fake.dart'; import '../../src/context.dart'; @@ -112,6 +113,52 @@ void main() { ProcessManager: () => FakeProcessManager.any(), FileSystem: () => fileSystem, }); + + testUsingContext('pub get triggers localizations generation when generate: true', () async { + final File pubspecFile = fileSystem.currentDirectory.childFile('pubspec.yaml') + ..createSync(); + pubspecFile.writeAsStringSync( + ''' + flutter: + generate: true + ''' + ); + fileSystem.currentDirectory.childFile('l10n.yaml') + ..createSync() + ..writeAsStringSync( + ''' + arb-dir: lib/l10n + ''' + ); + 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 PackagesGetCommand command = PackagesGetCommand('get', false); + final CommandRunner commandRunner = createTestCommandRunner(command); + + await commandRunner.run(['get']); + final FlutterCommandResult result = await command.runCommand(); + + expect(result.exitStatus, ExitStatus.success); + final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n')); + expect(outputDirectory.existsSync(), true); + expect(outputDirectory.childFile('app_localizations_en.dart').existsSync(), true); + expect(outputDirectory.childFile('app_localizations.dart').existsSync(), true); + }, overrides: { + Pub: () => pub, + ProcessManager: () => FakeProcessManager.any(), + FileSystem: () => fileSystem, + }); } class FakePub extends Fake implements Pub {