Make AppContext immutable and race-free (#15984)
This updates AppContext per the recommendations in #15352
Fixes #15352
diff --git a/packages/flutter_tools/lib/src/ios/cocoapods.dart b/packages/flutter_tools/lib/src/ios/cocoapods.dart
index e020c17..1307f00 100644
--- a/packages/flutter_tools/lib/src/ios/cocoapods.dart
+++ b/packages/flutter_tools/lib/src/ios/cocoapods.dart
@@ -31,7 +31,7 @@
brew upgrade cocoapods
pod setup''';
-CocoaPods get cocoaPods => context.putIfAbsent(CocoaPods, () => const CocoaPods());
+CocoaPods get cocoaPods => context[CocoaPods];
class CocoaPods {
const CocoaPods();
diff --git a/packages/flutter_tools/lib/src/ios/ios_workflow.dart b/packages/flutter_tools/lib/src/ios/ios_workflow.dart
index d561ff0..c44ce74 100644
--- a/packages/flutter_tools/lib/src/ios/ios_workflow.dart
+++ b/packages/flutter_tools/lib/src/ios/ios_workflow.dart
@@ -13,10 +13,10 @@
import 'cocoapods.dart';
import 'mac.dart';
-IOSWorkflow get iosWorkflow => context.putIfAbsent(IOSWorkflow, () => new IOSWorkflow());
+IOSWorkflow get iosWorkflow => context[IOSWorkflow];
class IOSWorkflow extends DoctorValidator implements Workflow {
- IOSWorkflow() : super('iOS toolchain - develop for iOS devices');
+ const IOSWorkflow() : super('iOS toolchain - develop for iOS devices');
@override
bool get appliesToHostPlatform => platform.isMacOS;
diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart
index 89497eb..7356716 100644
--- a/packages/flutter_tools/lib/src/ios/mac.dart
+++ b/packages/flutter_tools/lib/src/ios/mac.dart
@@ -35,9 +35,9 @@
// Homebrew.
const PythonModule kPythonSix = const PythonModule('six');
-IMobileDevice get iMobileDevice => context.putIfAbsent(IMobileDevice, () => const IMobileDevice());
+IMobileDevice get iMobileDevice => context[IMobileDevice];
-Xcode get xcode => context.putIfAbsent(Xcode, () => new Xcode());
+Xcode get xcode => context[Xcode];
class PythonModule {
const PythonModule(this.name);
diff --git a/packages/flutter_tools/lib/src/ios/xcodeproj.dart b/packages/flutter_tools/lib/src/ios/xcodeproj.dart
index e35d6aa..0144a2e 100644
--- a/packages/flutter_tools/lib/src/ios/xcodeproj.dart
+++ b/packages/flutter_tools/lib/src/ios/xcodeproj.dart
@@ -85,10 +85,7 @@
localsFile.writeAsStringSync(localsBuffer.toString());
}
-XcodeProjectInterpreter get xcodeProjectInterpreter => context.putIfAbsent(
- XcodeProjectInterpreter,
- () => new XcodeProjectInterpreter(),
-);
+XcodeProjectInterpreter get xcodeProjectInterpreter => context[XcodeProjectInterpreter];
/// Interpreter of Xcode projects.
class XcodeProjectInterpreter {