Skip to content

Commit f3d182f

Browse files
authored
[flutter_tools] Fix tool crash for map cast (#107648)
1 parent 9e2ef76 commit f3d182f

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

packages/flutter_tools/lib/src/build_system/targets/localizations.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class GenerateLocalizationsTarget extends Target {
6161
fileSystem: environment.fileSystem,
6262
);
6363

64-
final Map<String, Object> dependencies = json.decode(
64+
final Map<String, Object?> dependencies = json.decode(
6565
environment.buildDir.childFile(_kDependenciesFileName).readAsStringSync()
66-
) as Map<String, Object>;
66+
) as Map<String, Object?>;
6767
final List<Object?>? inputs = dependencies['inputs'] as List<Object?>?;
6868
final List<Object?>? outputs = dependencies['outputs'] as List<Object?>?;
6969
final Depfile depfile = Depfile(

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:flutter_tools/src/commands/packages.dart';
1010
import 'package:flutter_tools/src/dart/pub.dart';
1111
import 'package:flutter_tools/src/project.dart';
1212
import 'package:flutter_tools/src/reporting/reporting.dart';
13+
import 'package:flutter_tools/src/runner/flutter_command.dart';
1314
import 'package:test/fake.dart';
1415

1516
import '../../src/context.dart';
@@ -112,6 +113,52 @@ void main() {
112113
ProcessManager: () => FakeProcessManager.any(),
113114
FileSystem: () => fileSystem,
114115
});
116+
117+
testUsingContext('pub get triggers localizations generation when generate: true', () async {
118+
final File pubspecFile = fileSystem.currentDirectory.childFile('pubspec.yaml')
119+
..createSync();
120+
pubspecFile.writeAsStringSync(
121+
'''
122+
flutter:
123+
generate: true
124+
'''
125+
);
126+
fileSystem.currentDirectory.childFile('l10n.yaml')
127+
..createSync()
128+
..writeAsStringSync(
129+
'''
130+
arb-dir: lib/l10n
131+
'''
132+
);
133+
final File arbFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_en.arb'))
134+
..createSync(recursive: true);
135+
arbFile.writeAsStringSync(
136+
'''
137+
{
138+
"helloWorld": "Hello, World!",
139+
"@helloWorld": {
140+
"description": "Sample description"
141+
}
142+
}
143+
'''
144+
);
145+
146+
final PackagesGetCommand command = PackagesGetCommand('get', false);
147+
final CommandRunner<void> commandRunner = createTestCommandRunner(command);
148+
149+
await commandRunner.run(<String>['get']);
150+
final FlutterCommandResult result = await command.runCommand();
151+
152+
expect(result.exitStatus, ExitStatus.success);
153+
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('.dart_tool', 'flutter_gen', 'gen_l10n'));
154+
expect(outputDirectory.existsSync(), true);
155+
expect(outputDirectory.childFile('app_localizations_en.dart').existsSync(), true);
156+
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), true);
157+
}, overrides: <Type, Generator>{
158+
Pub: () => pub,
159+
ProcessManager: () => FakeProcessManager.any(),
160+
FileSystem: () => fileSystem,
161+
});
115162
}
116163

117164
class FakePub extends Fake implements Pub {

0 commit comments

Comments
 (0)