[flutter_tools] Remove fromPlatform from tests (#54152)

diff --git a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart
index 2c0472e..e087ec8 100644
--- a/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart
+++ b/packages/flutter_tools/test/commands.shard/hermetic/doctor_test.dart
@@ -33,9 +33,10 @@
 import '../../src/context.dart';
 import '../../src/testbed.dart';
 
-final Generator _kNoColorOutputPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())
-  ..localeName = 'en_US.UTF-8'
-  ..stdoutSupportsAnsi = false;
+final Generator _kNoColorOutputPlatform = () => FakePlatform(
+  localeName: 'en_US.UTF-8',
+  stdoutSupportsAnsi: false,
+);
 
 final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
   Platform: _kNoColorOutputPlatform,
diff --git a/packages/flutter_tools/test/commands.shard/permeable/analyze_once_test.dart b/packages/flutter_tools/test/commands.shard/permeable/analyze_once_test.dart
index 3b30266..e596d7b 100644
--- a/packages/flutter_tools/test/commands.shard/permeable/analyze_once_test.dart
+++ b/packages/flutter_tools/test/commands.shard/permeable/analyze_once_test.dart
@@ -20,7 +20,8 @@
 import '../../src/common.dart';
 import '../../src/context.dart';
 
-final Platform _kNoColorTerminalPlatform = FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
+final Platform _kNoColorTerminalPlatform = FakePlatform(
+  stdoutSupportsAnsi: false);
 
 void main() {
   String analyzerSeparator;
diff --git a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart
index f85d12f..4b048ae 100644
--- a/packages/flutter_tools/test/commands.shard/permeable/create_test.dart
+++ b/packages/flutter_tools/test/commands.shard/permeable/create_test.dart
@@ -31,6 +31,7 @@
 
 const String frameworkRevision = '12345678';
 const String frameworkChannel = 'omega';
+// TODO(fujino): replace FakePlatform.fromPlatform() with FakePlatform()
 final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
 final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
   Platform: _kNoColorTerminalPlatform,
diff --git a/packages/flutter_tools/test/general.shard/android/android_studio_test.dart b/packages/flutter_tools/test/general.shard/android/android_studio_test.dart
index 5d41771..b6d160c 100644
--- a/packages/flutter_tools/test/general.shard/android/android_studio_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/android_studio_test.dart
@@ -32,15 +32,17 @@
 class MockPlistUtils extends Mock implements PlistParser {}
 
 Platform linuxPlatform() {
-  return FakePlatform.fromPlatform(const LocalPlatform())
-    ..operatingSystem = 'linux'
-    ..environment = <String, String>{'HOME': homeLinux};
+  return FakePlatform(
+    operatingSystem: 'linux',
+    environment: <String, String>{'HOME': homeLinux},
+  );
 }
 
 Platform macPlatform() {
-  return FakePlatform.fromPlatform(const LocalPlatform())
-    ..operatingSystem = 'macos'
-    ..environment = <String, String>{'HOME': homeMac};
+  return FakePlatform(
+    operatingSystem: 'macos',
+    environment: <String, String>{'HOME': homeMac},
+  );
 }
 
 void main() {
diff --git a/packages/flutter_tools/test/general.shard/android/android_studio_validator_test.dart b/packages/flutter_tools/test/general.shard/android/android_studio_validator_test.dart
index fe89cba..45a5a86 100644
--- a/packages/flutter_tools/test/general.shard/android/android_studio_validator_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/android_studio_validator_test.dart
@@ -18,9 +18,10 @@
 const String home = '/home/me';
 
 Platform linuxPlatform() {
-  return FakePlatform.fromPlatform(const LocalPlatform())
-    ..operatingSystem = 'linux'
-    ..environment = <String, String>{'HOME': home};
+  return FakePlatform(
+    operatingSystem: 'linux',
+    environment: <String, String>{'HOME': home}
+  );
 }
 
 void main() {
diff --git a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
index 9ab855a..2abf127 100644
--- a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
@@ -601,9 +601,10 @@
 }
 
 Platform fakePlatform(String name) {
-  return FakePlatform
-    .fromPlatform(const LocalPlatform())
-    ..operatingSystem = name;
+  return FakePlatform(
+    environment: <String, String>{},
+    operatingSystem: name,
+  );
 }
 
 class FakeGradleUtils extends GradleUtils {
diff --git a/packages/flutter_tools/test/general.shard/android/gradle_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_test.dart
index 4906b66..67e3d07 100644
--- a/packages/flutter_tools/test/general.shard/android/gradle_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/gradle_test.dart
@@ -2633,9 +2633,11 @@
 }
 
 FakePlatform fakePlatform(String name) {
-  return FakePlatform.fromPlatform(const LocalPlatform())
-    ..operatingSystem = name
-    ..stdoutSupportsAnsi = false;
+  return FakePlatform(
+    environment: <String, String>{'HOME': '/path/to/home'},
+    operatingSystem: name,
+    stdoutSupportsAnsi: false,
+  );
 }
 
 class FakeGradleUtils extends GradleUtils {
diff --git a/packages/flutter_tools/test/general.shard/application_package_test.dart b/packages/flutter_tools/test/general.shard/application_package_test.dart
index 7e68724..cfed841 100644
--- a/packages/flutter_tools/test/general.shard/application_package_test.dart
+++ b/packages/flutter_tools/test/general.shard/application_package_test.dart
@@ -25,7 +25,7 @@
 import '../src/common.dart';
 import '../src/context.dart';
 
-final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
+final Generator _kNoColorTerminalPlatform = () => FakePlatform(stdoutSupportsAnsi: false);
 final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
   Platform: _kNoColorTerminalPlatform,
 };
diff --git a/packages/flutter_tools/test/general.shard/base/logger_test.dart b/packages/flutter_tools/test/general.shard/base/logger_test.dart
index 622ae2a..bdc0a7b 100644
--- a/packages/flutter_tools/test/general.shard/base/logger_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/logger_test.dart
@@ -15,7 +15,7 @@
 import '../../src/common.dart';
 import '../../src/mocks.dart' as mocks;
 
-final Platform _kNoAnsiPlatform = FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
+final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
 final String red = RegExp.escape(AnsiTerminal.red);
 final String bold = RegExp.escape(AnsiTerminal.bold);
 final String resetBold = RegExp.escape(AnsiTerminal.resetBold);
@@ -54,7 +54,7 @@
       final BufferLogger mockLogger = BufferLogger(
         terminal: AnsiTerminal(
           stdio:  mocks.MockStdio(),
-          platform: FakePlatform()..stdoutSupportsAnsi = true,
+          platform: FakePlatform(stdoutSupportsAnsi: true),
         ),
         outputPreferences: OutputPreferences.test(showColor: true),
       );
@@ -250,8 +250,8 @@
         AnsiStatus ansiStatus;
 
         setUp(() {
-          platform = FakePlatform.fromPlatform(testPlatform)..stdoutSupportsAnsi = false;
-          ansiPlatform = FakePlatform.fromPlatform(testPlatform)..stdoutSupportsAnsi = true;
+          platform = FakePlatform(stdoutSupportsAnsi: false);
+          ansiPlatform = FakePlatform(stdoutSupportsAnsi: true);
 
           terminal = AnsiTerminal(
             stdio: mockStdio,
@@ -749,7 +749,7 @@
       final Logger logger = StdoutLogger(
         terminal: AnsiTerminal(
           stdio: mockStdio,
-          platform: FakePlatform()..stdoutSupportsAnsi = true,
+          platform: FakePlatform(stdoutSupportsAnsi: true),
         ),
         stdio: mockStdio,
         outputPreferences: OutputPreferences.test(showColor: true),
diff --git a/packages/flutter_tools/test/general.shard/base/net_test.dart b/packages/flutter_tools/test/general.shard/base/net_test.dart
index ec69406..8b4ee6b 100644
--- a/packages/flutter_tools/test/general.shard/base/net_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/net_test.dart
@@ -25,7 +25,7 @@
     testLogger = BufferLogger(
       terminal: AnsiTerminal(
         stdio: MockStdio(),
-        platform: FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false,
+        platform: FakePlatform(stdoutSupportsAnsi: false),
       ),
       outputPreferences: OutputPreferences.test(),
     );
@@ -35,7 +35,7 @@
     return Net(
       httpClientFactory: () => client,
       logger: testLogger,
-      platform: FakePlatform.fromPlatform(const LocalPlatform()),
+      platform: FakePlatform(),
     );
   }
 
@@ -160,10 +160,11 @@
         ArgumentError('test exception handling'),
       ),
       logger: testLogger,
-      platform: FakePlatform.fromPlatform(const LocalPlatform())
-        ..environment = <String, String>{
+      platform: FakePlatform(
+        environment: <String, String>{
           'FLUTTER_STORAGE_BASE_URL': 'example.invalid',
         },
+      ),
     );
     String error;
     FakeAsync().run((FakeAsync time) {
diff --git a/packages/flutter_tools/test/general.shard/base/process_test.dart b/packages/flutter_tools/test/general.shard/base/process_test.dart
index 27569b1..a7485ea 100644
--- a/packages/flutter_tools/test/general.shard/base/process_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/process_test.dart
@@ -85,7 +85,7 @@
       mockLogger = BufferLogger(
         terminal: AnsiTerminal(
           stdio: MockStdio(),
-          platform: FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false,
+          platform: FakePlatform(stdoutSupportsAnsi: false),
         ),
         outputPreferences: OutputPreferences(wrapText: true, wrapColumn: 40),
       );
@@ -248,7 +248,7 @@
       testLogger = BufferLogger(
         terminal: AnsiTerminal(
           stdio: MockStdio(),
-          platform: FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false,
+          platform: FakePlatform(stdinSupportsAnsi: false),
         ),
         outputPreferences: OutputPreferences(wrapText: true, wrapColumn: 40),
       );
diff --git a/packages/flutter_tools/test/general.shard/base/user_messages_test.dart b/packages/flutter_tools/test/general.shard/base/user_messages_test.dart
index b60c3f6..01e259a 100644
--- a/packages/flutter_tools/test/general.shard/base/user_messages_test.dart
+++ b/packages/flutter_tools/test/general.shard/base/user_messages_test.dart
@@ -11,12 +11,9 @@
 typedef _InstallationMessage = String Function(Platform);
 
 void main() {
-  final FakePlatform macPlatform = FakePlatform.fromPlatform(const LocalPlatform());
-  macPlatform.operatingSystem = 'macos';
-  final FakePlatform linuxPlatform = FakePlatform.fromPlatform(const LocalPlatform());
-  linuxPlatform.operatingSystem = 'linux';
-  final FakePlatform windowsPlatform = FakePlatform.fromPlatform(const LocalPlatform());
-  windowsPlatform.operatingSystem = 'windows';
+  final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos');
+  final FakePlatform linuxPlatform = FakePlatform(operatingSystem: 'linux');
+  final FakePlatform windowsPlatform = FakePlatform(operatingSystem: 'windows');
 
   void _checkInstallationURL(_InstallationMessage message) {
     expect(message(macPlatform), contains('https://flutter.dev/docs/get-started/install/macos#android-setup'));
diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart
index a4933f0..426b004c 100644
--- a/packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart
+++ b/packages/flutter_tools/test/general.shard/build_system/targets/icon_tree_shaker_test.dart
@@ -23,9 +23,7 @@
 import '../../../src/context.dart';
 import '../../../src/mocks.dart' as mocks;
 
-final Platform _kNoAnsiPlatform =
-    FakePlatform.fromPlatform(const LocalPlatform())
-      ..stdoutSupportsAnsi = false;
+final Platform _kNoAnsiPlatform = FakePlatform(stdoutSupportsAnsi: false);
 
 void main() {
   BufferLogger logger;
diff --git a/packages/flutter_tools/test/general.shard/ios/devices_test.dart b/packages/flutter_tools/test/general.shard/ios/devices_test.dart
index a5fa58d..7fabcad 100644
--- a/packages/flutter_tools/test/general.shard/ios/devices_test.dart
+++ b/packages/flutter_tools/test/general.shard/ios/devices_test.dart
@@ -28,12 +28,9 @@
 import '../../src/mocks.dart';
 
 void main() {
-  final FakePlatform macPlatform = FakePlatform.fromPlatform(const LocalPlatform());
-  macPlatform.operatingSystem = 'macos';
-  final FakePlatform linuxPlatform = FakePlatform.fromPlatform(const LocalPlatform());
-  linuxPlatform.operatingSystem = 'linux';
-  final FakePlatform windowsPlatform = FakePlatform.fromPlatform(const LocalPlatform());
-  windowsPlatform.operatingSystem = 'windows';
+  final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos');
+  final FakePlatform linuxPlatform = FakePlatform(operatingSystem: 'linux');
+  final FakePlatform windowsPlatform = FakePlatform(operatingSystem: 'windows');
 
   group('IOSDevice', () {
     final List<Platform> unsupportedPlatforms = <Platform>[linuxPlatform, windowsPlatform];
diff --git a/packages/flutter_tools/test/general.shard/ios/mac_test.dart b/packages/flutter_tools/test/general.shard/ios/mac_test.dart
index 727b25c..7c23577 100644
--- a/packages/flutter_tools/test/general.shard/ios/mac_test.dart
+++ b/packages/flutter_tools/test/general.shard/ios/mac_test.dart
@@ -23,7 +23,7 @@
 import '../../src/common.dart';
 import '../../src/context.dart';
 
-final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
+final Generator _kNoColorTerminalPlatform = () => FakePlatform(stdoutSupportsAnsi: false);
 final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
   Platform: _kNoColorTerminalPlatform,
 };
diff --git a/packages/flutter_tools/test/general.shard/ios/simulators_test.dart b/packages/flutter_tools/test/general.shard/ios/simulators_test.dart
index 79cdf77..df8ff64 100644
--- a/packages/flutter_tools/test/general.shard/ios/simulators_test.dart
+++ b/packages/flutter_tools/test/general.shard/ios/simulators_test.dart
@@ -44,8 +44,10 @@
   MemoryFileSystem fileSystem;
 
   setUp(() {
-    osx = FakePlatform.fromPlatform(const LocalPlatform());
-    osx.operatingSystem = 'macos';
+    osx = FakePlatform(
+      environment: <String, String>{},
+      operatingSystem: 'macos',
+    );
     fileSystem = MemoryFileSystem();
     fsUtils = FileSystemUtils(fileSystem: fileSystem, platform: osx);
   });
diff --git a/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart b/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart
index 81944db..e86afb2 100644
--- a/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart
+++ b/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart
@@ -36,7 +36,7 @@
 
   setUp(() {
     processManager = mocks.MockProcessManager();
-    platform = fakePlatform('macos');
+    platform = FakePlatform(operatingSystem: 'macos');
     fileSystem = MemoryFileSystem();
     fileSystem.file(xcodebuild).createSync(recursive: true);
     terminal = MockAnsiTerminal();
@@ -125,7 +125,7 @@
   });
 
   testWithoutContext('xcodebuild isInstalled is false when not on MacOS', () {
-    final Platform platform = fakePlatform('notMacOS');
+    final Platform platform = FakePlatform(operatingSystem: 'notMacOS');
     xcodeProjectInterpreter = XcodeProjectInterpreter(
       logger: logger,
       fileSystem: fileSystem,
@@ -175,6 +175,7 @@
   });
 
   testWithoutContext('xcodebuild build settings is empty when xcodebuild failed to get the build settings', () async {
+    platform.environment = Map<String, String>.unmodifiable(<String, String>{});
     when(processManager.runSync(
               argThat(contains(xcodebuild)),
               workingDirectory: anyNamed('workingDirectory'),
@@ -190,6 +191,7 @@
       flakes: 1,
       delay: delay + const Duration(seconds: 1),
     );
+    platform.environment = Map<String, String>.unmodifiable(<String, String>{});
 
     expect(await xcodeProjectInterpreter.getBuildSettings(
                 '', '', timeout: delay),
@@ -422,7 +424,7 @@
     FakePlatform platform;
 
     setUp(() {
-      platform = fakePlatform('ignored');
+      platform = FakePlatform();
     });
 
     testWithoutContext('environment variables as Xcode build settings', () {
@@ -447,7 +449,7 @@
       fs = MemoryFileSystem();
       mockArtifacts = MockLocalEngineArtifacts();
       mockProcessManager = MockProcessManager();
-      macOS = fakePlatform('macos');
+      macOS = FakePlatform(operatingSystem: 'macos');
       fs.file(xcodebuild).createSync(recursive: true);
     });
 
@@ -803,10 +805,6 @@
   });
 }
 
-FakePlatform fakePlatform(String name) {
-  return FakePlatform.fromPlatform(const LocalPlatform())..operatingSystem = name;
-}
-
 class MockLocalEngineArtifacts extends Mock implements LocalEngineArtifacts {}
 class MockProcessManager extends Mock implements ProcessManager {}
 class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {}
diff --git a/packages/flutter_tools/test/general.shard/macos/xcode_test.dart b/packages/flutter_tools/test/general.shard/macos/xcode_test.dart
index e070232..3074db6 100644
--- a/packages/flutter_tools/test/general.shard/macos/xcode_test.dart
+++ b/packages/flutter_tools/test/general.shard/macos/xcode_test.dart
@@ -253,8 +253,7 @@
     });
 
     group('available devices', () {
-      final FakePlatform macPlatform = FakePlatform.fromPlatform(const LocalPlatform());
-      macPlatform.operatingSystem = 'macos';
+      final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos');
 
       testWithoutContext('Xcode not installed', () async {
         when(mockXcode.isInstalledAndMeetsVersionCheck).thenReturn(false);
@@ -447,8 +446,7 @@
     });
 
     group('diagnostics', () {
-      final FakePlatform macPlatform = FakePlatform.fromPlatform(const LocalPlatform());
-      macPlatform.operatingSystem = 'macos';
+      final FakePlatform macPlatform = FakePlatform(operatingSystem: 'macos');
 
       testWithoutContext('Xcode not installed', () async {
         when(mockXcode.isInstalledAndMeetsVersionCheck).thenReturn(false);
diff --git a/packages/flutter_tools/test/src/mocks.dart b/packages/flutter_tools/test/src/mocks.dart
index ec57c94..2d7b8a4 100644
--- a/packages/flutter_tools/test/src/mocks.dart
+++ b/packages/flutter_tools/test/src/mocks.dart
@@ -29,6 +29,7 @@
 
 import 'common.dart';
 
+// TODO(fujino): replace FakePlatform.fromPlatform() with FakePlatform()
 final Generator kNoColorTerminalPlatform = () {
   return FakePlatform.fromPlatform(
     const LocalPlatform()