Repository navigation
Re-evaluation of assertions removal for const widgets #108248
Description
Activity
the ubiquitous presence of like unnecessary assertion like
: assert(children != null);(e.g.) really baffles me.I understand the
backwards compatibility with non-nullsafe code,
but sound null safety was introduced long time ago (March 3, 2021),
I'm not sure if there is any point in allowing compatibility with legacy codeIt's clearly a technical debt and it does, albeit in limited fashion,
have consequences in terms of performance
@albertodev01 just provided an example of itReacted by Gustav TredeReacted by Gustav Trede- addedin triagePresently being triaged by the triage teamPresently being triaged by the triage teamframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.c: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterand removedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Jul 25, 2022 The Dart team is also planning to remove support to non-null-safe code:
Reacted by Francesco Iapicca and Gustav TredeWe plan to remove these asserts from the framework when dart discontinues non-null safety.
Reacted by Francesco Iapicca, Gustav Trede and Alberto- addedP3Issues that are less important to the Flutter projectIssues that are less important to the Flutter project
on Jul 26, 2022 There is an interesting update: dart-lang/sdk#49530
Looks like we should be able to remove those assertions somewhere around mid-2023 when Dart 3 will be out
Reacted by Francesco IapiccaReacted by Gustav TredeUpdate: with the upcoming Dart 3 version, it may be a good time now to make this change.
It seems that this issue might be addressed here: #118837
Reacted by Gustav Trede and Francesco IapiccaDear god, finally :)
It seems that this issue might be addressed here: #118837
Yeah, I am working on this as part of that issue.
Reacted by AlbertoWe can close this as it's finally done 🎉
This is not quite done yet, but it is in progress. I am going to leave this open until its truly done.
- addedr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
on Feb 1, 2023 This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Mar 3, 2023
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:This is valid but only the
childrenlist is constant, not the whole widget. In other words, we can't do this:There already was an issue (#88359) to address this but it was closed due to this reason:
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,Stackand much moreconst-able.A
Containerfor example could also beconstif some assertions were removed on its constructors.Proposal
Remove the
assertstatement here forMultiChildRenderObjectWidget, which would make lots of widgetsconst.