Skip to content

Re-evaluation of assertions removal for const widgets #108248

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.

Activity

  1. iapicca commented on Jul 25, 2022

    @iapicca

    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 code

    It's clearly a technical debt and it does, albeit in limited fashion,
    have consequences in terms of performance
    @albertodev01 just provided an example of it

  2. added
    in triagePresently being triaged by the triage team
    frameworkflutter/packages/flutter repository. See also f: labels.
    c: proposalA detailed proposal for a change to Flutter
    and removed
    in triagePresently being triaged by the triage team
    on Jul 25, 2022
  3. albertodev01 commented on Jul 26, 2022

    @albertodev01
    ContributorAuthor
  4. goderbauer commented on Jul 26, 2022

    @goderbauer
    Member

    We plan to remove these asserts from the framework when dart discontinues non-null safety.

  5. added
    P3Issues that are less important to the Flutter project
    on Jul 26, 2022
  6. albertodev01 commented on Sep 1, 2022

    @albertodev01
    ContributorAuthor

    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

  7. albertodev01 commented on Jan 19, 2023

    @albertodev01
    ContributorAuthor

    Update: 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

  8. gustav3d commented on Jan 20, 2023

    @gustav3d

    Dear god, finally :)

  9. goderbauer commented on Jan 20, 2023

    @goderbauer
    Member

    It seems that this issue might be addressed here: #118837

    Yeah, I am working on this as part of that issue.

  10. albertodev01 commented on Jan 23, 2023

    @albertodev01
    ContributorAuthor

    We can close this as it's finally done 🎉

  11. goderbauer commented on Jan 23, 2023

    @goderbauer
    Member

    This is not quite done yet, but it is in progress. I am going to leave this open until its truly done.

  12. self-assigned this
    on Jan 23, 2023
  13. added
    r: fixedIssue is closed as already fixed in a newer version
    on Feb 1, 2023
  14. github-actions commented on Mar 3, 2023

    @github-actions

    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 -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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