Skip to content

Commit

Permalink
plugin_ffi warn about lack of platform support (#106813)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcharkes authored Jun 29, 2022
1 parent 0df4885 commit e4bde83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/flutter_tools/lib/src/commands/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class CreateCommand extends CreateBase {
'main.dart',
));
globals.printStatus('Your module code is in $relativeMainPath.');
} else if (generateMethodChannelsPlugin) {
} else if (generateMethodChannelsPlugin || generateFfiPlugin) {
final String relativePluginPath = globals.fs.path.normalize(globals.fs.path.relative(projectDirPath));
final List<String> requestedPlatforms = _getUserRequestedPlatforms();
final String platformsString = requestedPlatforms.join(', ');
Expand All @@ -400,7 +400,8 @@ class CreateCommand extends CreateBase {
if (platformsToWarn.isNotEmpty) {
_printWarningDisabledPlatform(platformsToWarn);
}
_printPluginAddPlatformMessage(relativePluginPath);
final String template = generateMethodChannelsPlugin ? 'plugin' : 'plugin_ffi';
_printPluginAddPlatformMessage(relativePluginPath, template);
} else {
// Tell the user the next steps.
final FlutterProject project = FlutterProject.fromDirectory(globals.fs.directory(projectDirPath));
Expand Down Expand Up @@ -715,9 +716,9 @@ You've created a plugin project that doesn't yet support any platforms.
''');
}

void _printPluginAddPlatformMessage(String pluginPath) {
void _printPluginAddPlatformMessage(String pluginPath, String template) {
globals.printStatus('''
To add platforms, run `flutter create -t plugin --platforms <platforms> .` under $pluginPath.
To add platforms, run `flutter create -t $template --platforms <platforms> .` under $pluginPath.
For more information, see https://flutter.dev/go/plugin-platforms.
''');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,22 @@ void main() {
Logger: ()=> logger,
});

testUsingContext('created FFI plugin supports no platforms should print `no platforms` message', () async {
Cache.flutterRoot = '../..';

final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);

await runner.run(<String>['create', '--no-pub', '--template=plugin_ffi', projectDir.path]);
expect(logger.errorText, contains(_kNoPlatformsMessage));
expect(logger.statusText, contains('To add platforms, run `flutter create -t plugin_ffi --platforms <platforms> .` under ${globals.fs.path.normalize(globals.fs.path.relative(projectDir.path))}.'));
expect(logger.statusText, contains('For more information, see https://flutter.dev/go/plugin-platforms.'));

}, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(),
Logger: ()=> logger,
});

testUsingContext('created plugin with no --platforms flag should not print `no platforms` message if the existing plugin supports a platform.', () async {
Cache.flutterRoot = '../..';

Expand Down

0 comments on commit e4bde83

Please sign in to comment.