Skip to content

Challenge with Flutter 3.7 breaking none nullable .of changes #119499

@rydmike

Description

@rydmike

Flutter 3.7 .of breaking changes

Flutter 3.7 added a large amount of breaking changes by making many nullable static Nnnn.of(context) functions non-nullable and introducing Nnnn.maybeOf(context) replacements.

This is similar to the big breaking change done in Flutter 2.0.0 described here https://docs.flutter.dev/release/breaking-changes/eliminating-nullok-parameters.

The change is understandable, both for consistence and efficiency of the non nullable variant. Apparently many where forgotten in the in Flutter 2.0.0 migration and new ones using the old style have even even been added after it.

These changes were not mentioned as planned and upcoming for next (this 3.7) release. However some of them were indeed listed as upcoming in a future release via https://docs.flutter.dev/release/breaking-changes/supplemental-maybeOf-migration.

This PR #114120 contains many of the commits that seem to match some of the above listed cases. Some others are not mentioned, like e.g. Overlay.of that has an earlier PR here #110811.

For applications the change is not a big issue. As long as there is a dart fix for all of them, the migration can be pretty smooth and quick. Additionally most of the impacted APIs are reasonably rare.

However, for packages that may prefer to support at least one major release backwards compatibility, these breaking changes are more troublesome. Converting a broken previously nullable .of to a nullable .maybeOf breaks backwards compatibility with all previous Flutter versions and requires a version constraint of min Flutter 3.7.0. Likewise keeping the none nullable .of results in a analyzer warning, package pub score reduction and most importantly a potentially troublesome use-case, if the nullable version was actually needed.

In the PR a potential soft approach was mentioned here #114120 (review) by @goderbauer.

I mentioned the same thought in a tweet here and likewise in the PR comment after discovering this here.

The staged softer approach would imo have been more considerate, by first adding the nullable maybeOf to Flutter 3.7, while still keeping the .of methods nullable as well. Then later switching the .of methods to none nullable, e.g. 4.0.0 could have been a nice future release for that. Would have been a logical point to introduce the breaking changes, just as 2.0.0 was for the bulk of the previous ones. Would have given time to migrate packages to .maybeOf over at least one stable overlap.

Repeat of Flutter 2.0.0 migration maybeOf package challenges?

The previous major .maybeOf breaking changes in Flutter 2.0.0 saw a lot of issues and challenges in packages due to this. Particularly with transitive dependencies not using the right version with maybeOf, and updates to packages simply just lagging behind a long time, blocking moving on to latest Flutter stable release. I am concerned we might face a similar situation again. Maybe I worry too much.

Options?

@gspencergoog and @goderbauer, I am aware that the ship has probably sailed on this topic and we will all just have to bite the hard break bullet. Unless of course the impacted .of:s are reverted to be nullable and the nullable .maybeOf kept. Then the staged approach would effectively be introduced.

I opened this as an issue to discuss and see what our options are, if any, based on suggestion by @timsneath's tweet comment here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: null-safetySupport for Dart's null safety featurec: API breakBackwards-incompatible API changesc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions