Skip to content

Add template for plugin projects. - #9076

Merged
jakobr-google merged 3 commits into
flutter:masterfrom
jakobr-google:plugin-template
Mar 30, 2017
Merged

jakobr-google merged 3 commits into
flutter:masterfrom
jakobr-google:plugin-template

Conversation

@jakobr-google

Copy link
Copy Markdown
Contributor

Plugin projects are created by running flutter create --plugin <name>.

By default, an example app is also created in the plugin project. This can be disabled by adding --no-example. The example app is created using the normal 'create' template, which has been modified to allow for conditional plugin code.

Modified the android package name to match package naming conventions (all lower-case, and must match the directory name).

Plugin projects are created by running `flutter create --plugin <name>`.

By default, an example app is also created in the plugin project. This can be disabled by adding `--no-example`. The example app is created using the normal 'create' template, which has been modified to allow for conditional plugin code.

Modified the android package name to match package naming conventions (all lower-case, and must match the directory name).
@jakobr-google jakobr-google added the p: tooling Affects the flutter_plugin_tools package label Mar 29, 2017
@devoncarew

Copy link
Copy Markdown
Contributor

Some initial thoughts:

Plugin projects are created by running flutter create --plugin .

Perhaps use --plugin-project, or --template=plugin? The --template=foo arg would be nice in that create would always be using a template, just w/o an explicit arg it would default to the regular project template.

By default, an example app is also created in the plugin project. This can be disabled by adding --no-example

What about not having a --no-example flag? Users can always delete the content, and fewer options is nicer.

@collinjackson

Copy link
Copy Markdown
Contributor

Lately I've been putting "Plugin" at the end of the plugin class names on the native side, to make them more distinguishable from the native classes that plugins often wrap, e.g. FirebaseDatabasePlugin vs FirebaseDatabase, ImagePickerPlugin vs ImagePicker

There are other available workarounds such as class prefixing (on iOS) and namespacing (on Android) but having "Plugin" the name makes it more clear what the class does, I think.

@collinjackson collinjackson left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I kind of agree with Devon that fewer options is better and it's easy for plugin authors to just delete the example if they don't want one.

@jakobr-google

Copy link
Copy Markdown
Contributor Author

Removed the --example flag, and added a Plugin suffix to the native classes.

I prefer --plugin over --plugin-project since it's shorter, and what else would we be creating? --template= sounds nice, but there are really two templates involved in creating a plugin, 'plugin' and 'create' (for the example app).

@jakobr-google
jakobr-google merged commit f34f8a3 into flutter:master Mar 30, 2017
@jakobr-google
jakobr-google deleted the plugin-template branch March 30, 2017 10:39
@jakobr-google jakobr-google mentioned this pull request Mar 30, 2017
@devoncarew

Copy link
Copy Markdown
Contributor

but there are really two templates involved in creating a plugin, 'plugin' and 'create'

Yes, but it makes things a bit more explicit. Instead of slightly altering the mode for create, we're selecting between two options.

super.initState();
{{pluginDartClass}}.platformVersion.then((String platformVersion) {
setState(() {
_platformVersion = platformVersion;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is buggy. If the _MyHomePageState state has been disposed before the future completes, it'll assert.

Is there a way to cancel a pending platform request? We should do so in the state's dispose() function so that it doesn't unexpectedly complete here in that case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no way to cancel. Added mounted check in #9458.

children: [
new Text('Running on: $_platformVersion\n'),
new Text(
'Button tapped $_counter time${ _counter == 1 ? '' : 's' }.'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't match the style guide

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #9458

),
body: new Center(
{{#withPluginHook}}
child: new Column(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to add Column here we need to add comments explaining what's going on, especially if we add mainAxisSize as well.

I'm worried about having multiple versions of this template. We have four now (normal, driver, plugin, driver+plugin). We have micromanaged the creation of this template based on the usability studies; the more versions we have the more studies we're going to need to actually test them all. This doesn't scale.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to do about the 'multiple versions' part. We deliberately did the conditional approach, as the alternative would have been to fork ALL ~60 files in /templates/create/ into /templates/plugin/ which would have been a lot less scalable.

Do you have a better idea than the conditional approach?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 0.02 is that we should have two templates, a normal app project and a plugin project. The normal project should include driver support, example unit tests, ... - things we think are best practice and that we'd like to lead users towards.

@mit-mit mit-mit Apr 19, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have that. This is for the example app inside a plugin (the /example/ dir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. I thought this was discussing the flutter create case, where we do have a matrix of options.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is that right now the main.dart.tmpl file is effectively forked into four versions:

  • the one generated by flutter create
  • the one generated by flutter create --driver or some such
  • the one generated by flutter create --plugin or some such
  • the one hypothetically generated by flutter create --plugin --driver or some such (I suspect we don't ever generate this today, I haven't checked)

We have carefully crafted the one generated by flutter create based on usability feedback to optimise for the first hour experience. The other versions haven't been tested and I'm worried about what will happen as the needs for these various versions diverge.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, I'm not suggesting forking more. That wouldn't address my concerns (it would make in fact them worse, for the reasons discussed above by @mit-mit). My concerns are not concrete, they are merely fear for the future. :-)

@mit-mit mit-mit Apr 20, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the #9458 PR i just sent. I think the more clear separation in main.dart makes it a little more manageable.

@Hixie Hixie mentioned this pull request Apr 18, 2017
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

p: tooling Affects the flutter_plugin_tools package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants