Unverified Commit 5ba2830c authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tool][gallery] Standardize target platform override behavior in tool...

[flutter_tool][gallery] Standardize target platform override behavior in tool and update flutter gallery to support it (#46206)
parent 187c89b6
......@@ -70,6 +70,12 @@ class _GalleryAppState extends State<GalleryApp> {
model = AppStateModel()..loadProducts();
}
@override
void reassemble() {
_options = _options.copyWith(platform: defaultTargetPlatform);
super.reassemble();
}
@override
void dispose() {
_timeDilationTimer?.cancel();
......
......@@ -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: <String, Object>{
'value': nextPlatform,
'value': platform,
});
printStatus('Switched operating system to $nextPlatform');
printStatus('Switched operating system to $platform');
} on vmservice.RPCError {
return;
}
......
......@@ -363,16 +363,7 @@ class FlutterDevice {
}
Future<String> 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';
}
}
......@@ -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<AssertionError>()));
});
}
class MockFlutterDevice extends Mock implements FlutterDevice {}
......
......@@ -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: <String, Object>{'value': 'android'})).called(1);
args: <String, Object>{'value': 'fuchsia'})).called(1);
}));
test('cleanup of resources is safe to call multiple times', () => testbed.run(() async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment