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.

Stateless Widget template has warnings

See original GitHub issue

Describe 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?

image

To Reproduce

  1. flutter create to start a new empty project.
  2. 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.”

image

Then, once you fix that, then it gives you a new warning:

image “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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
goderbauercommented, May 19, 2021

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.

1reaction
DanTupcommented, May 19, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

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