Stateless Widget template has warnings
See original GitHub issueDescribe the bug A clear and concise description of what the bug is.
If you use the stateless widget template (which I think comes from Dart-Code?) it now ends up with warnings as of the latest Flutter default template?
To Reproduce
flutter create
to start a new empty project.- Type ‘stls’ and let it autocomplete to the stateless widget template.
Expected behavior Should not have any analyzer warnings.
First it gives you a warning about missing “key” parameter in constructor: “Use key in widget constructors.”
Then, once you fix that, then it gives you a new warning:
“Prefer declaring const constructors on @immutable
classes.”
Versions (please complete the following information):
[√] Flutter (Channel master, 2.3.0-2.0.pre.237, on Microsoft Windows [Version 10.0.19041.928], locale en-US)
• Flutter version 2.3.0-2.0.pre.237 at C:\Users\micro\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c71e8bacfd (76 minutes ago), 2021-05-16 17:44:01 -0400
• Engine revision 0c9ffcc623
• Dart version 2.14.0 (build 2.14.0-edge.a527411e5100a0a4f48c4009087a1b988aa784af)
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.4)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.9.31205.134
• Windows 10 SDK version 10.0.19041.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:16 (8 by maintainers)
Top Results From Across the Web
flutter - How to avoid warning when defining member in widget?
I have to define _parameters to store parameter from Home() (constructor) so the widget can get parameters from outside. But it causes a...
Read more >Adding interactivity to your Flutter app
A widget is either stateful or stateless. If a widget can change—when a user interacts with it, for example—it's stateful. A stateless widget...
Read more >Stateless Flutter. Providing for Purists | by Richard Shepherd
In this article we'll look at the classic Flutter starter project — but with Stateless Widgets only. The purpose is to demonstrate how...
Read more >Alert Dialog box in Flutter - GeeksforGeeks
Flutter provides its own show Dialog widget which is used to show Dialog box. Example: ... class MyApp extends StatelessWidget {.
Read more >Flutter : Stateless Widget Vs Stateful Widget | Easy to learn
Get the insights of flutter Stateless and Stateful widgets with a simple example.Join this channel to get access to ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
While we don’t have a way to configure it, I would also be in favor of generating null-safe code. It is what we recommend for new projects and we also want to nudge people to migrate their existing projects.
Based on the changes at https://github.com/flutter/flutter-intellij/pull/5405, I think IntelliJ probably has a similar dilemma. The merged templates do not include a
?
but I think that will produce errors (that the variable has no default value and is not marked nullable). I think putting the?
s in would result in any existing projects that are not opted-in to null-safety getting warnings that?
is not valid.