Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable custom "flutter create" templates #77104

Open
Hixie opened this issue Mar 2, 2021 · 26 comments
Open

Enable custom "flutter create" templates #77104

Hixie opened this issue Mar 2, 2021 · 26 comments
Labels
c: new feature Nothing broken; request for a new capability P3 Issues that we currently consider unimportant team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels. triaged-tool Triaged by Flutter Tool team

Comments

@Hixie
Copy link
Contributor

Hixie commented Mar 2, 2021

It would be interesting to enable the creation of custom templates usable with flutter create, which don't require that the templates be actually in our repo. For example, if Rive wanted to create a template that showed off how to use Rive animations in Flutter, they could do so without having to land code in the flutter/flutter repo. (VGV have done something similar: https://verygood.ventures/blog/flutter-starter-app-very-good-core-cli)

Should we enable anyone to create a template, or should we have an allowlist? There's a risk of people tricking people into running hostile code if we allow anyone to host templates. We could have two tiers, one for template sets whose creators we trust, and one which gets a big warning.

How do we identify templates? We could do it by URL, or by some well-established pattern e.g. domain:path, like example.com:demoapp which expands to example.com/.flutter-templates/demoapp.zip or some such.

How do we host templates? zip files?

How do we avoid having to include redundant files? e.g. it'd be nice if most templates could be just lib/main.dart and pubspec.yaml.

@Hixie Hixie added c: new feature Nothing broken; request for a new capability tool Affects the "flutter" command-line tool. See also t: labels. P3 Issues that we currently consider unimportant labels Mar 2, 2021
@jonahwilliams
Copy link
Member

Some thoughts:

Many kinds of templates have tags/conditionals, but I'm not sure how either the CLI or Flutter IDEs would provide those without a lowest common denominator approach like --template-value=foo=bar

If most templates don't want to deal with platform configuration, then we'd need to include that by default. If we start supporting custom platform configurations, we'd need to account for them when writing migrators https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/base/project_migrator.dart#L15

@tarobins
Copy link
Contributor

tarobins commented Mar 3, 2021

A specific template I'd like, which would be probably a way I'd use this feature, is to have a template like the app starter template but without all the comments, and maybe not even some of the code.

When I want to just quickly try something in flutter, I end up creating and app and then deleting a bunch of the comments and some of the code cause that just clutters up my experiment work. Not saying the comments aren't good; they are very helpful for a new users, but I'd rather flutter create an even more bare-bones app in some cases.

[added] It would also be super helpful if I could host this template somewhere other than my local machine cause I often do flutter experiments on different machines, so I'd like to just point at some url. I realize this feature could introduce a whole load of security issues, so maybe not feasible, but anyway. Though maybe the security issue is no different than a pub package?

@pedromassangocode
Copy link

When I want to just quickly try something in flutter, I end up creating and app and then deleting a bunch of the comments and some of the code cause that just clutters up my experiment work.

I agree. Something like flutter create foo --no-comments would be great.

@Hixie
Copy link
Contributor Author

Hixie commented Mar 5, 2021

Though maybe the security issue is no different than a pub package?

I hadn't thought of using pub to host these, that's brilliant. It would reduce all the problems here to a previously solved problem. (Or at least, a previously-existing problem.)

@jonahwilliams, regarding tags/conditionals, can you elaborate? What tags and conditionals do we use in the current templates? I suspect it might be ok to not support this generally for the new templates but I am not sure if I'm missing something obvious.

@jonahwilliams
Copy link
Member

For example, suppose your template generates a test file alongside your project. Its generally the case that we use package imports for test files, so the import would need to configured based on the chosen project name.

@Hixie
Copy link
Contributor Author

Hixie commented Mar 5, 2021

I guess the question is whether we need such flags beyond a standard set like "project name".

@AliHG
Copy link

AliHG commented Mar 5, 2021

Are these templates gonna contain guide lines for app architecture and state management like in Jetpack MVVM ??

@AliHG
Copy link

AliHG commented Mar 5, 2021

@Hixie I saw your talk in flutter engage but i don't know if this is what you meant or not

@Hixie
Copy link
Contributor Author

Hixie commented Mar 5, 2021

They could, but the one I mentioned during the Q&A is actually in review right now and wouldn't use this (it would just be built in). That should land soon and should be in the next stable.

@YazeedAlKhalaf
Copy link
Contributor

YazeedAlKhalaf commented Apr 22, 2021

I agree with having custom templates, like a place for user-defined templates. For example, I use an architecture called Stacked, most of the time I just copy and paste code which is annoying when starting a new project. If I could for example run flutter create --template stacked my_awesome_flutter_app. It would make creating projects way easier! 🚀

The templates could be in some site just like pub.dev where people publish their own templates and share them with the people. Though there should be some limitations so it does not get spammed. Or maybe use GitHub repos for templates 🤔.

Should we enable anyone to create a template, or should we have an allowlist? There's a risk of people tricking people into running hostile code if we allow anyone to host templates. We could have two tiers, one for template sets whose creators we trust, and one which gets a big warning.

I suggest allowing only trusted people and also the template should be reviewed by some designated people before being recommended to the people. And also there could be a way for custom templates if the user wants to use his own template 😉

@Hixie
Copy link
Contributor Author

Hixie commented Apr 22, 2021

Yeah, using pub.dev seems like the best proposal so far. We could literally just have these be a special kind of package: you run flutter create --from-package foobar and it fetches and expands the foobar package from pub. Might make sense for these to be an overlay on top of the existing templates so that people can just include the parts they want.

@RandalSchwartz
Copy link

When I want to just quickly try something in flutter, I end up creating and app and then deleting a bunch of the comments and some of the code cause that just clutters up my experiment work.

I imagine more lines have been collectively deleted from the counter app than have gone into any other single codebase. :)

@isAlmogK
Copy link

isAlmogK commented May 8, 2021

Following, I would also like to see this. My goal would be to have a way to set up a template project with files, folders, structure, packages maybe even initial routing that can be generated via a command line like Yoman in JS. Reduce the boilerplate of setup, currently working on my 6th app in Flutter.

@felangel
Copy link
Contributor

felangel commented May 20, 2021

The functionality you're describing is very similar to what we have done in very_good_cli and regarding the template creation and generation we use package:mason. With mason developers are able to bundle their templates which would make it easier to publish a single template bundle to pub.dev rather than multiple files/directories. We would love to work together on this if you think it makes sense 👍

@isAlmogK
Copy link

@felangel thanks

@isAlmogK
Copy link

@felangel any tutorials on how you did this

@felangel
Copy link
Contributor

felangel commented May 20, 2021

@felangel any tutorials on how you did this

I'd recommend taking a look at the README and example. We're working on a more detailed tutorial which should be available in the next few weeks but in the meantime I'm happy to answer any questions.

@felangel
Copy link
Contributor

FYI we just published a blog post on mason 😄

@felangel
Copy link
Contributor

felangel commented May 28, 2021

@Hixie I'd love to work together on this if that's a possibility. It would be awesome to have first-party support for templates as part of the pub ecosystem!

@Hixie
Copy link
Contributor Author

Hixie commented May 28, 2021

If you are interested in implementing this please feel free to jump in! For something like this it's probably a good idea to write a design doc first; see https://github.com/flutter/flutter/wiki/Chat#design-documents.

@jonahwilliams
Copy link
Member

And to @Hixie 's point on a design doc - this isn't really a formality. I am personally not convinced that custom create templates in the flutter tool add a lot of value over a new tool like the very_good_cli. You should be prepared to make the case that isn't true, and to additionally explain how it would be maintained without breaking as the tool libraries/source update over time.

@felangel
Copy link
Contributor

felangel commented Feb 25, 2022

Just wanted to give an update...

I've been actively working on package:mason and package:mason_cli over the last year to make it easy for developers to define/consume reusable templates. With mason, developers can create and distribute templates (bricks) either via local path, git, or remote registry (heavily inspired by pub.dev, stagehand, cookie cutter, and more.). Templates can be bundled and baked into existing CLIs as well. very_good_cli is an example of a Dart CLI that leverages mason internally for the templating/rendering of bundled templates.

I would love to collaborate with the Flutter team to leverage an open source tool like mason within package:flutter_tools because mason already offers support for many of the requested features that would make using/defining custom flutter templates easier.

@flutter-triage-bot
Copy link

This issue is assigned but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

@omishah
Copy link

omishah commented Sep 20, 2023

this is really an important feature that should be available 👍

@flutter-triage-bot flutter-triage-bot bot added the Bot is counting down the days until it unassigns the issue label Nov 25, 2023
@flutter-triage-bot
Copy link

This issue is assigned to @christopherfujino but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

@flutter-triage-bot
Copy link

This issue was assigned to @christopherfujino but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.

@flutter-triage-bot flutter-triage-bot bot removed the Bot is counting down the days until it unassigns the issue label Feb 5, 2024
@christopherfujino christopherfujino added the triaged-tool Triaged by Flutter Tool team label Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability P3 Issues that we currently consider unimportant team-tool Owned by Flutter Tool team tool Affects the "flutter" command-line tool. See also t: labels. triaged-tool Triaged by Flutter Tool team
Projects
Status: Planned Q3
Development

No branches or pull requests