diff --git a/examples/flutter_gallery/lib/gallery/app.dart b/examples/flutter_gallery/lib/gallery/app.dart index dc570ff2237..9c3b57f7dd9 100644 --- a/examples/flutter_gallery/lib/gallery/app.dart +++ b/examples/flutter_gallery/lib/gallery/app.dart @@ -70,6 +70,12 @@ class _GalleryAppState extends State { model = AppStateModel()..loadProducts(); } + @override + void reassemble() { + _options = _options.copyWith(platform: defaultTargetPlatform); + super.reassemble(); + } + @override void dispose() { _timeDilationTimer?.cancel(); diff --git a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart index 949c1a459ed..218bc0c942c 100644 --- a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart +++ b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart @@ -235,23 +235,12 @@ abstract class ResidentWebRunner extends ResidentRunner { final vmservice.Response response = await _vmService ?.callServiceExtension('ext.flutter.platformOverride'); final String currentPlatform = response.json['value'] as String; - String nextPlatform; - switch (currentPlatform) { - case 'android': - nextPlatform = 'iOS'; - break; - case 'iOS': - nextPlatform = 'android'; - break; - } - if (nextPlatform == null) { - return; - } + final String platform = nextPlatform(currentPlatform, featureFlags); await _vmService?.callServiceExtension('ext.flutter.platformOverride', args: { - 'value': nextPlatform, + 'value': platform, }); - printStatus('Switched operating system to $nextPlatform'); + printStatus('Switched operating system to $platform'); } on vmservice.RPCError { return; } diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index e666af6c139..aaadc550f65 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -363,16 +363,7 @@ class FlutterDevice { } Future togglePlatform({ String from }) async { - String to; - switch (from) { - case 'iOS': - to = 'android'; - break; - case 'android': - default: - to = 'iOS'; - break; - } + final String to = nextPlatform(from, featureFlags); for (FlutterView view in views) { await view.uiIsolate.flutterPlatformOverride(to); } @@ -1319,3 +1310,26 @@ class DebugConnectionInfo { final Uri wsUri; final String baseUri; } + +/// Returns the next platform value for the switcher. +/// +/// These values must match what is available in +/// packages/flutter/lib/src/foundation/binding.dart +String nextPlatform(String currentPlatform, FeatureFlags featureFlags) { + switch (currentPlatform) { + case 'android': + return 'iOS'; + case 'iOS': + return 'fuchsia'; + case 'fuchsia': + if (featureFlags.isMacOSEnabled) { + return 'macOS'; + } + return 'android'; + case 'macOS': + return 'android'; + default: + assert(false); // Invalid current platform. + return 'android'; + } +} diff --git a/packages/flutter_tools/test/general.shard/resident_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_runner_test.dart index 0dd418d6141..187991fc473 100644 --- a/packages/flutter_tools/test/general.shard/resident_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_runner_test.dart @@ -704,6 +704,14 @@ void main() { Device device, }) async => mockVMService, })); + + test('nextPlatform moves through expected platforms', () { + expect(nextPlatform('android', TestFeatureFlags()), 'iOS'); + expect(nextPlatform('iOS', TestFeatureFlags()), 'fuchsia'); + expect(nextPlatform('fuchsia', TestFeatureFlags()), 'android'); + expect(nextPlatform('fuchsia', TestFeatureFlags(isMacOSEnabled: true)), 'macOS'); + expect(() => nextPlatform('unknown', TestFeatureFlags()), throwsA(isInstanceOf())); + }); } class MockFlutterDevice extends Mock implements FlutterDevice {} diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart index a747a831908..405e43899b8 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart @@ -773,9 +773,9 @@ void main() { await residentWebRunner.debugTogglePlatform(); - expect(testLogger.statusText, contains('Switched operating system to android')); + expect(testLogger.statusText, contains('Switched operating system to fuchsia')); verify(mockVmService.callServiceExtension('ext.flutter.platformOverride', - args: {'value': 'android'})).called(1); + args: {'value': 'fuchsia'})).called(1); })); test('cleanup of resources is safe to call multiple times', () => testbed.run(() async {