Skip to content

Re-evaluation of assertions removal for const widgets #108248

@albertodev01

Description

@albertodev01

Use case

Right now, for backwards compatibility with non-nullsafe code, there still are some assertions that make some code impossible to be marked as const. For example:

Row(
  children: const [
    Text('Hello'),
    Text('World'),
  ]
),

This is valid but only the children list is constant, not the whole widget. In other words, we can't do this:

const Row(
  children: [
    Text('Hello'),
    Text('World'),
  ]
),

There already was an issue (#88359) to address this but it was closed due to this reason:

Is the reasoning here that we can remove the check because in an NNBD world List children can never contain null? We've left these kind of null checks in the code base for now because not all apps have migrated to NNBD yet and they still need these asserts for proper error reporting.

That was a valid point but almost one year has passed since then and I think the team could re-evaluate investigating if it's worth removing those assertions. They would make Row, Column, Stack and much more const-able.

A Container for example could also be const if some assertions were removed on its constructors.

Proposal

Remove the assert statement here for MultiChildRenderObjectWidget, which would make lots of widgets const.

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions