Added warning when not enabled platform is selected (#73205)
This commit is contained in:
@@ -300,13 +300,19 @@ class CreateCommand extends CreateBase {
|
||||
} else if (_getSupportedPlatformsInPlugin(projectDir).isEmpty){
|
||||
_printNoPluginMessage();
|
||||
}
|
||||
_printAddPlatformMessage(relativePluginPath);
|
||||
|
||||
final List<String> platformsToWarn = _getPlatformWarningList(requestedPlatforms);
|
||||
if (platformsToWarn.isNotEmpty) {
|
||||
_printWarningDisabledPlatform(platformsToWarn);
|
||||
}
|
||||
_printPluginAddPlatformMessage(relativePluginPath);
|
||||
} else {
|
||||
// Tell the user the next steps.
|
||||
final FlutterProject project = FlutterProject.fromPath(projectDirPath);
|
||||
final FlutterProject app = project.hasExampleApp ? project.example : project;
|
||||
final String relativeAppPath = globals.fs.path.normalize(globals.fs.path.relative(app.directory.path));
|
||||
final String relativeAppMain = globals.fs.path.join(relativeAppPath, 'lib', 'main.dart');
|
||||
final List<String> requestedPlatforms = _getUserRequestedPlatforms();
|
||||
|
||||
// Let them know a summary of the state of their tooling.
|
||||
globals.printStatus('''
|
||||
@@ -322,7 +328,13 @@ To enable null safety, type:
|
||||
|
||||
Your $application code is in $relativeAppMain.
|
||||
''');
|
||||
// Show warning if any selected platform is not enabled
|
||||
final List<String> platformsToWarn = _getPlatformWarningList(requestedPlatforms);
|
||||
if (platformsToWarn.isNotEmpty) {
|
||||
_printWarningDisabledPlatform(platformsToWarn);
|
||||
}
|
||||
}
|
||||
|
||||
return FlutterCommandResult.success();
|
||||
}
|
||||
|
||||
@@ -500,21 +512,64 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
|
||||
void _printPluginUpdatePubspecMessage(String pluginPath, String platformsString) {
|
||||
globals.printStatus('''
|
||||
You need to update $pluginPath/pubspec.yaml to support $platformsString.
|
||||
|
||||
''', emphasis: true, color: TerminalColor.red);
|
||||
}
|
||||
|
||||
void _printNoPluginMessage() {
|
||||
globals.printError('''
|
||||
You've created a plugin project that doesn't yet support any platforms.
|
||||
|
||||
''');
|
||||
}
|
||||
|
||||
void _printAddPlatformMessage(String pluginPath) {
|
||||
void _printPluginAddPlatformMessage(String pluginPath) {
|
||||
globals.printStatus('''
|
||||
To add platforms, run `flutter create -t plugin --platforms <platforms> .` under $pluginPath.
|
||||
For more information, see https://flutter.dev/go/plugin-platforms.
|
||||
|
||||
''');
|
||||
}
|
||||
|
||||
// returns a list disabled, but requested platforms
|
||||
List<String> _getPlatformWarningList(List<String> requestedPlatforms) {
|
||||
final List<String> platformsToWarn = <String>[
|
||||
if (requestedPlatforms.contains('web') && !featureFlags.isWebEnabled)
|
||||
'web',
|
||||
if (requestedPlatforms.contains('macos') && !featureFlags.isMacOSEnabled)
|
||||
'macos',
|
||||
if (requestedPlatforms.contains('windows') && !featureFlags.isWindowsEnabled)
|
||||
'windows',
|
||||
if (requestedPlatforms.contains('linux') && !featureFlags.isLinuxEnabled)
|
||||
'linux',
|
||||
];
|
||||
|
||||
return platformsToWarn;
|
||||
}
|
||||
|
||||
void _printWarningDisabledPlatform(List<String> platforms) {
|
||||
final List<String> desktop = <String>[];
|
||||
final List<String> web = <String>[];
|
||||
|
||||
for (final String platform in platforms) {
|
||||
if (platform == 'web') {
|
||||
web.add(platform);
|
||||
} else if (platform == 'macos' || platform == 'windows' || platform == 'linux') {
|
||||
desktop.add(platform);
|
||||
}
|
||||
}
|
||||
|
||||
if (desktop.isNotEmpty) {
|
||||
final String platforms = desktop.length > 1 ? 'platforms' : 'platform';
|
||||
final String verb = desktop.length > 1 ? 'are' : 'is';
|
||||
|
||||
globals.printStatus('''
|
||||
The desktop $platforms: ${desktop.join(', ')} $verb currently not supported on your local environment.
|
||||
For more details, see: https://flutter.dev/desktop
|
||||
''');
|
||||
}
|
||||
if (web.isNotEmpty) {
|
||||
globals.printStatus('''
|
||||
The web is currently not supported on your local environment.
|
||||
For more details, see: https://flutter.dev/docs/get-started/web
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import '../../src/testbed.dart';
|
||||
const String _kNoPlatformsMessage = 'You\'ve created a plugin project that doesn\'t yet support any platforms.\n';
|
||||
const String frameworkRevision = '12345678';
|
||||
const String frameworkChannel = 'omega';
|
||||
const String _kDisabledPlatformRequestedMessage = 'currently not supported on your local environment.';
|
||||
// TODO(fujino): replace FakePlatform.fromPlatform() with FakePlatform()
|
||||
final Generator _kNoColorTerminalPlatform = () => FakePlatform.fromPlatform(const LocalPlatform())..stdoutSupportsAnsi = false;
|
||||
final Map<Type, Generator> noColorTerminalOverride = <Type, Generator>{
|
||||
@@ -2352,6 +2353,74 @@ void main() {
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('should show warning when disabled platforms are selected while creating a plugin', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=android,ios,web,windows,macos,linux', projectDir.path]);
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', projectDir.path]);
|
||||
expect(logger.statusText, contains(_kDisabledPlatformRequestedMessage));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext("shouldn't show warning when only enabled platforms are selected while creating a plugin", () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=android,ios,windows', projectDir.path]);
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', projectDir.path]);
|
||||
expect(logger.statusText, isNot(contains(_kDisabledPlatformRequestedMessage)));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('should show warning when disabled platforms are selected while creating a app', () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', '--platforms=android,ios,web,windows,macos,linux', projectDir.path]);
|
||||
await runner.run(<String>['create', '--no-pub', projectDir.path]);
|
||||
expect(logger.statusText, contains(_kDisabledPlatformRequestedMessage));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext("shouldn't show warning when only enabled platforms are selected while creating a app", () async {
|
||||
Cache.flutterRoot = '../..';
|
||||
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
|
||||
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
|
||||
|
||||
final CreateCommand command = CreateCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--platforms=windows', projectDir.path]);
|
||||
await runner.run(<String>['create', '--no-pub', '--template=plugin', projectDir.path]);
|
||||
expect(logger.statusText, isNot(contains(_kDisabledPlatformRequestedMessage)));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
FeatureFlags: () => TestFeatureFlags(isWindowsEnabled: true, isAndroidEnabled: false, isIOSEnabled: false),
|
||||
Logger: () => logger,
|
||||
});
|
||||
|
||||
testUsingContext('flutter create prints note about null safety', () async {
|
||||
await _createProject(
|
||||
projectDir,
|
||||
|
||||
Reference in New Issue
Block a user