[flutter_tool][gallery] Standardize target platform override behavior in tool and update flutter gallery to support it (#46206)

This commit is contained in:
Jonah Williams
2019-12-12 15:20:52 -08:00
committed by GitHub
parent 187c89b69d
commit 5ba2830c83
5 changed files with 43 additions and 26 deletions

View File

@@ -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;
}

View File

@@ -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';
}
}