question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Create Constructor" for Widgets

See original GitHub issue

Hey hey 😃 I find myself creating a lot of Widget constructors, and I end up repeating the same manual process over and over. I thought it might be cool if this could be part of the Flutter IntelliJ plugin!

tl;dr – “Create Constructor” should produce an idiomatic constructor for Widgets.

Full Steps:

  1. type stless to create a Stateless Widget
  2. Add a final field to the Widget
  3. Put cursor over the final field
  4. Alt-Enter
  5. Select “Create Constructor for Final Field”, produces: MyWidget(this.title);
  6. Change this to conform with the normal Flutter rules: MyWidget({Key key, this.title}) : super(key: key);
    • All fields optional
    • Includes a Key and proper call to super.

Not a huge deal, but I’ve done it so much recently I thought it’d be nice if it could be generated for me 😃 Thanks again for all the hard work – the plugin is getting sooooo good.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
devxpycommented, Jul 10, 2018

@leslieharland Alt + Enter

Read more comments on GitHub >

github_iconTop Results From Across the Web

StatelessWidget class - widgets library - Flutter - Dart API docs
Use const widgets where possible, and provide a const constructor for the widget so that users of the widget can also do so....
Read more >
Flutter Dart constructor - Stack Overflow
It is the constructor of the Align widget. class Align extends SingleChildRenderObjectWidget { // constructor const Align({ Key key, // named ...
Read more >
Flutter: Passing Widgets using Constructor Arguments in ...
In this video, I'll talk about how we can use constructor arguments to pass widgets while creating Stateless and Stateful widgets.
Read more >
‍ Flutter| Using Super Constructor in Custom Widget Design ...
We will take care to write clean code while creating custom widgets. The important part is how to use the “Super Constructor” that...
Read more >
Custom Constructors for StatefulWidgets? - Google Groups
Therefore, I have custom constructor for this widget that takes in a DateTime object, ... of the SDK authors to create so many...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found