-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
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.