Skip to content

Remove unneeded Widget type annotations in templates #176098

@mit-mit

Description

@mit-mit

The flutter create templates creates a build method that looks like this (a few details omitted):

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: .center,
          children: <Widget>[
            const Text('You have pushed the button this many times:'),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
    );
  }

The <Widget> annotation on the collection passed into children seems like unnessasary verbosity. Flutter devs are quite aware of Widgets being the basic building block. And the analyzer is perfectly capable of catching non-widgets being passed in, see e.g.:

Image

I thus suggest we get rid of that type annotation.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions