Skip to content

Ask which platforms to create the project for when running Flutter: New Project #4271

Closed

Description

@mpekurin

Describe the solution you'd like
Show a checkbox list of available platforms when the command is executed (similar to Settings Sync: Configure... and Remote: Install Local Extensions in...):
image
Also it would be nice to have Flutter: Manage Platforms command which essentially will do the same thing but in an existing project.

Describe alternatives you've considered
While it's possible to set required platforms via --platforms when running flutter create in a terminal even after the project is created, it would be a bit easier and faster to set them during a project creation in vscode.

Activity

  1. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on Nov 16, 2022
  2. DanTup commented on Nov 16, 2022

    @DanTup
    Member

    I like this idea, although I'm also hesitant to add an extra mandatory step in the flow.

    It would be a little less discoverable, but I wonder if it would be better in the "settings" accessible from the cog when providing a name:

    Screenshot 2022-11-16 at 15 04 24

    Screenshot 2022-11-16 at 15 04 30

    The only niggle is right now those settings are actually just modifying your local settings and are not specific to the project you're creating. I don't know whether it'd make sense to follow that pattern for this.

    Also it would be nice to have Flutter: Manage Platforms command which essentially will do the same thing but in an existing project.

    There is an existing way to add platforms to an existing project, though not in bulk. If you click the device manager and there's a platform that hasn't been set up, trying to set it as the active device will prompt you to add it:

    Screenshot 2022-11-16 at 15 08 32

    This just runs flutter create with that platform to add the missing files. I don't think there's a nice way to invoke Flutter and ask for a platform to be removed though (although deleting the folder works, I don't know if that's a good assumption to code into the VS Code extension).

    @jacob314 @gspencergoog any opinions on the above (adding platform selection as a mandatory step vs having it accessible from an icon when entering the name)?

  3. gspencergoog commented on Nov 16, 2022

    @gspencergoog

    I don't think there's a nice way to invoke Flutter and ask for a platform to be removed though (although deleting the folder > works, I don't know if that's a good assumption to code into the VS Code extension).

    Right, there's no easy way to do that because the user may have modified the code in that directory and be sad when it disappears (although they did ask to remove it, so maybe it's OK). If we can determine that the user really really is fine with deleting possibly modified code, then we could remove the directory.

  4. DanTup commented on Nov 16, 2022

    @DanTup
    Member

    If we can determine that the user really really is fine with deleting possibly modified code, then we could remove the directory.

    I wonder if it's better to just leave them to do this manually for now, to avoid any risk with us doing it.

    Any opinions on the dialog up above? In particular, having it as an extra step for all Flutter: New Projects versus in a settings dialog?

    We could possibly do both - have it in the cog, but also prompt the first time, with a divider at the bottom and another checkbox for "use these without asking in future" (and you could use the cog or go directly into VS Code settings to change these "defaults" you've set)? Maybe I'll mock that up and see how it looks.

  5. added this to the v3.54.0 milestone on Nov 16, 2022
  6. added
    in commandsRelates to commands (usually invoked from the command Palette)
    on Nov 16, 2022
  7. gspencergoog commented on Nov 16, 2022

    @gspencergoog

    I like the "do both" approach, if that works.

  8. mpekurin commented on Nov 17, 2022

    @mpekurin
    Author

    There is an existing way to add platforms to an existing project, though not in bulk. If you click the device manager and there's a platform that hasn't been set up, trying to set it as the active device will prompt you to add it.

    It suggests only the platform a user is currently using and web.

    Right, there's no easy way to do that because the user may have modified the code in that directory and be sad when it disappears.

    I wonder if it's better to just leave them to do this manually for now, to avoid any risk with us doing it.

    Since running flutter create --platforms ... edits .metadata, probably an action that removes a platform should execute flutter create anyway and then ask the user what to do with the directory via a notification:
    image

    We could possibly do both - have it in the cog, but also prompt the first time, with a divider at the bottom and another checkbox for "use these without asking in future" (and you could use the cog or go directly into VS Code settings to change these "defaults" you've set)? Maybe I'll mock that up and see how it looks.

    In addition to this I would add a setting like dart.flutterCreateForDefaultPlatforms with false value as default. This will allow a user to set defaults but still show the prompt each time they create a project if they want.

    If true the extension behaves as you've described but without asking the first time (since false is the default value of the setting). So basically it behaves as it does now except it reads platforms from the settings instead of creating for all of them. A user can change platforms via the cog menu, which also have Set as Defaults (writes the selected platforms to dart.flutterDefaultPlatforms) and Always Ask (sets dart.flutterCreateForDefaultPlatforms to false) buttons.

    If false it prompts each time a project is created with defaults preselected. The prompt also have Set as Defaults (writes the selected platforms to dart.flutterDefaultPlatforms) and Don't Ask Again (sets dart.flutterCreateForDefaultPlatforms to false) buttons.

  9. mpekurin commented on Nov 17, 2022

    @mpekurin
    Author

    The solution I see after reading the comments

    Add the following settings with the respective default values:

    "dart.flutterDefaultPlatforms": [
        "ios",
        "android",
        "windows",
        "linux",
        "macos",
        "web"
    ],
    "dart.flutterCreateForDefaultPlatforms": false

    While it's possible to use flutter config --[no-]enable-platform instead of dart.flutterDefaultPlatforms, I think storing the setting in vscode would be better since this allows to sync it, doesn't touch the global config and probably it'll be a bit easier to implement.

    Modify Flutter: New Project command:

    • Add Platforms to the cog menu. When it's pressed, show a checkbox list of available platforms with the platforms listed in dart.flutterDefaultPlatforms preselected. Show Set as Defaults, Always Ask (if dart.flutterCreateForDefaultPlatforms == true) and Apply buttons above the list.
    • If dart.flutterCreateForDefaultPlatforms is set to false, show the list each time the command is executed but instead of Always Ask button display Don't Ask Again button.
    • Always Ask button sets dart.flutterCreateForDefaultPlatforms to false, Don't Ask Again button sets the setting to true. Set as Defaults writes the selected platforms into dart.flutterDefaultPlatforms.

    image

    Add Flutter: Manage Platforms or Flutter: Recreate Project command which will:

    1. Show the same checkbox list as in Flutter: New Project command (but with different title) with Set as Defaults and Apply buttons above the list.
    2. Execute flutter create . --platforms ....
    3. Ask the user if they want to remove the directories created for the removed platforms via a notification.

    image

  10. DanTup commented on Nov 28, 2022

    @DanTup
    Member

    @mpekurin

    There is an existing way to add platforms to an existing project, though not in bulk. If you click the device manager and there's a platform that hasn't been set up, trying to set it as the active device will prompt you to add it.

    It suggests only the platform a user is currently using and web.

    Sounds like something isn't right here.. in the screenshot I posted above (#4271 (comment)) I have "enable macos" as an option when the macos folder is missing.

    Since running flutter create --platforms ... edits .metadata, probably an action that removes a platform should execute flutter create anyway and then ask the user what to do with the directory via a notification:

    If the flutter tool gained a way to do this, it may makes sense. I'm not sure it's worthwhile adding an action in the VS Code extension that just deletes a folder and modifies that file though (because it's adding implementation details about .metadata to the VS Code extension I'd rather not have).

    I don't know what the implications are of deleting the folder without modifying .metadata though. It always seemed to be fine for me, but I'm not a heavy Flutter user so that might not mean much.

    In addition to this I would add a setting like dart.flutterCreateForDefaultPlatforms with false value as default. This will allow a user to set defaults but still show the prompt each time they create a project if they want.

    I agree that defaults should not be tied to whether or not we show the prompt.

    While it's possible to use flutter config --[no-]enable-platform instead of dart.flutterDefaultPlatforms

    Agreed - I don't think we should assume that all enabled platforms are what the user wants as defaults for each newly created project.

    image

    Unfortunately we can't build UI like this in VS Code. The options are very limited. It's likely we'd just need to have another set of checkboxes at the bottom (after a divider). I'll mock something up and post back shortly.

  11. DanTup commented on Nov 28, 2022

    @DanTup
    Member

    I'm splitting this issue up a little, because there are a few things that need doing to achieve what's discussed above and some of them are easier than others (some require a bit of refacoring):

  12. modified the milestones: v3.54.0, v3.56.0 on Nov 28, 2022
  13. mpekurin commented on Nov 30, 2022

    @mpekurin
    Author

    @DanTup

    Sounds like something isn't right here.. in the screenshot I posted above (#4271 (comment)) I have "enable macos" as an option when the macos folder is missing.

    I guess you're using macOS so you see the option, but the menu won't suggest you to enable Windows and Linux support. At least it works like this on Windows: the menu doesn't suggest iOS, Linux and macOS. Enabling a platform from this menu causes the extension to run flutter create . without a --platforms argument thus adding all platforms to the project though.
    image

    If the flutter tool gained a way to do this, it may makes sense. I'm not sure it's worthwhile adding an action in the VS Code extension that just deletes a folder and modifies that file though (because it's adding implementation details about .metadata to the VS Code extension I'd rather not have).

    .metadata should be modified by flutter create command, not by vscode itself. The action will be useful for adding platforms to an existing project as well. So if the action is added it should:

    1. Check which platform folders are present in the project folder (e. g. ["android", "ios", "linux"]).
    2. Compare the user's selection (e. g. ["android", "ios", "macos"]) with the list from the previous step and detect which platforms are to be removed.
    3. Ask the user if they want to remove the detected platforms (e. g. ["linux"]). If yes, remove the folders.
    4. Run flutter create --platforms with the platforms selected by the user. It'll modify .metadata as necessary and create the missing folders. E. g. flutter create --platforms=android,ios,macos . run after the previous steps will remove linux from .metadata, add macos into it and create the macos folder.

    I don't know what the implications are of deleting the folder without modifying .metadata though. It always seemed to be fine for me, but I'm not a heavy Flutter user so that might not mean much.

    As I understand it, platforms supported by a project depend only on platform folders presented in the project folder, and the platform list in .metadata is used for migration to a newer flutter version.

    Unfortunately we can't build UI like this in VS Code. The options are very limited. It's likely we'd just need to have another set of checkboxes at the bottom (after a divider). I'll mock something up and post back shortly.

    Probably it's possible to use QuickInputButton's with tooltips. They look like this:
    image

    And thanks for your efforts.

  14. DanTup commented on Nov 30, 2022

    @DanTup
    Member

    Enabling a platform from this menu causes the extension to run flutter create . without a --platforms argument thus adding all platforms to the project though.

    Ugh, I suspect I've broken this with the changes for #4284. I noticed we could pass --platform to template types that didn't support it, but we don't have a template type when enabling platforms later. I've opened #4294 about this and will ship a fix in the coming days.

    Probably it's possible to use QuickInputButton's with tooltips. They look like this:

    Yeah, we use these icons to get to the settings (see https://dartcode.org/releases/v3-54/#flutter-new-project-platform-defaults), but they're not very obvious. I think having additional checkboxes below a divider might be better, but it'll need some testing.

    Your flow above sounds fairly reasonable, although I'd prefer to avoid assumptions about the folders being tied to a platform being enabled. Flutter added a specific getSupportedPlatforms API to the daemon to avoid us having to make that assumption (I can imagine a world where if your platform-specific code is completely generic with no customisations, you wouldn't need to have this folder). Perhaps if we wanted to do this we could put it into Flutter so it could support flutter create --no-platforms windows to disable a platform and have it do whatever is required (such as deleting the folder). As Greg says, it's a bit risky deleting potentially customised files though.

    There were also some questions recently about whether we could improve this new project experience by having a custom web view (eg. a small web app built in Flutter). This would avoid some of the restrictions of the VS Code UI. It needs some testing though, so I might see what that experience might be like before doing too much more on the existing command.

  15. mpekurin commented on Nov 30, 2022

    @mpekurin
    Author

    Although I'd prefer to avoid assumptions about the folders being tied to a platform being enabled.

    Yeah, I didn't know about getSupportedPlatforms.

    Perhaps if we wanted to do this we could put it into Flutter so it could support flutter create --no-platforms windows.

    This totally makes sense.

    As Greg says, it's a bit risky deleting potentially customised files though.

    If it won't overcomplicate things a prompt may be used. If --no-platforms is added to Flutter then it may be complemented by --yes or --agree option which will allow to delete folders silently. This way flutter create --no-platforms ... run manually by a user will ask them about deleting platform folders (e. g. This action will delete ... folders. Continue? [Y/n]), while the extension (and other tools) will be able to prompt the user via UI and then run flutter create --no-platforms ... --agree.

    However, a further discussion of this feature requires a new issue in flutter I guess.

  16. modified the milestones: v3.56.0, v3.58.0 on Dec 19, 2022
  17. modified the milestones: v3.58.0, v3.60.0 on Jan 18, 2023
  18. modified the milestones: v3.60.0, On Deck on Feb 27, 2023
  19. modified the milestones: On Deck, v3.136.0 on May 27, 2026
  20. DanTup commented on May 27, 2026

    @DanTup
    Member

    With #6064, we'll now show the platform selector automatically during the Create flow, with a "Don't ask next time" option that toggles the new setting dart.flutterCreatePromptForPlatforms that controls this.

    image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in commandsRelates to commands (usually invoked from the command Palette)in flutterRelates to running Flutter appsis enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions