Skip to content

Code generation #20865

Closed
Closed

Description

@rrousselGit

build and source_gen are the reference for code-generation in dart.

Flutter having disabled dart:mirror, code generation is very important (notably for serialization).
The problem is, the current code-generation workflow is a bit tiresome

First, the command to generate code is the following:

flutter pub pub run build_runner build

There's far too many repetitions for a relatively common command. It would be much better to have the following (and maybe removing build_runner from the project direct dependencies):

flutter generate --watch

This would make things much smoother and intuitive

Once we've got this command we can then add a few flags to run:

flutter run --[no-]generate

Which would run a flutter generate --watch in background. So that there's no need for multiple terminal instances.

As a bonus point, flutter run could detect if the project has a dependency or not on build (even indirect), and decides accordingly whether to generate dart files or not.

Activity

  1. zoechi commented on Aug 21, 2018

    @zoechi
    Contributor

    I think this is related to #13834 perhaps a dup of the linked #9870

  2. added
    c: new featureNothing broken; request for a new capability
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Aug 21, 2018
  3. jonahwilliams commented on Aug 21, 2018

    @jonahwilliams
    Contributor

    While I agree we should improve this workflow, as a temporary workaround I would just create an alias for the build runner command.

    alias pbr="flutter pub pub run build_runner build"

  4. rrousselGit commented on Aug 21, 2018

    @rrousselGit
    ContributorAuthor

    I think this is related to #13834 perhaps a dup of the linked #9870

    That can help. But I fear that the linked PR may make project bootstrap harder. And this issue is not so much about plugins or builds hooks.

    In the end, almost all projects will want a [de]serializer. And since the official solution is code-generation, I think flutter should make it a "working out of the box" experience.

  5. Hixie commented on Dec 12, 2018

    @Hixie
    Contributor

    We will want code gen to be integrated into Flutter's build system so that it can run before analysis in the analyzer server, before tests in flutter test, and during hot reload.

  6. changed the title [-]Improve code-generation workflow[/-] [+]Code generation[/+] on Dec 12, 2018
  7. added this to the milestone on Dec 12, 2018
  8. jonahwilliams commented on Dec 12, 2018

    @jonahwilliams
    Contributor

    We could do so by basing flutter's internal build steps (test, hot reload, build) on package:build. This would allow us to integrate with existing builders and source gen, as have a better story for testing our own build

  9. tvolkert commented on Dec 19, 2018

    @tvolkert
    Contributor

    Depends on #25377

  10. rrousselGit commented on Jan 11, 2019

    @rrousselGit
    ContributorAuthor

    I recently faced Flutter throwing an exception because hot-reload applied before a code-generator could finish.

    The solution is likely in implementing this issue. But is there anything I can do in the meantime to prevent this from reproducing?

  11. jonahwilliams commented on Jan 25, 2019

    @jonahwilliams
    Contributor
  12. jonahwilliams commented on Mar 22, 2019

    @jonahwilliams
    Contributor

    Closed via #29399. See #27141 for more info

  13. github-actions commented on Aug 15, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: new featureNothing broken; request for a new capabilitytoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions