Skip to content

refactor: Standardize nullability of the EnumProperty type parameter on event diagnostic messages [proposal]#181112

Closed
luanpotter wants to merge 1 commit into
flutter:masterfrom
luanpotter:luan.enum-prop
Closed

refactor: Standardize nullability of the EnumProperty type parameter on event diagnostic messages [proposal]#181112
luanpotter wants to merge 1 commit into
flutter:masterfrom
luanpotter:luan.enum-prop

Conversation

@luanpotter

Copy link
Copy Markdown
Contributor

On the debugFillProperties chain used to print debug representation of events, the EnumProperty extends the cornerstone DiagnosticsProperty with a type T. The type T is not meant to be nullable because the values are always supportive of nulls regardless of the value of T (i.e. value is of type T?). This can be seen on the vast majority of cases and children of DiagnosticsProperty which do not specify Foo?.

However EnumProperty was defined to support a nullable T, which cause some usages (but not most) to specify the null version of the enum (such as EnumProperty<PointerDeviceKind?>), which was not consistent even with many other usages. This makes it identical to the field definition, which can be null and thus is defined as PointerDeviceKind?, but it is ultimately not necessary with how DiagnosticsProperty defines it.

This PR removes the permissibility of nullable T on EnumProperty, fixing the few existing violations which makes them standardized with all other usages of EnumProperty (and DiagnosticsProperty in general).

This should have absolutely no change in behaviour whatsoever, and this "debug to string" property is covered by the debug_test.dart and should be unchanged.

This was extracted from #176968 in an attempt to simplify it.

Note: this does not fix all other children or direct usages of DiagnosticsProperty, which there are a few. Those can be done as followups if desired.

Note: if the intent is to have the type of T to match the type of the field exactly (including nullability), I think it would make sense to then change the type of value to be just T - that way it "forces" the user to specify Foo? if the type is nullable Foo?. That is a good alternative as well, that if preferred, I can pivot to.

Pre-launch Checklist

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: gestures flutter/packages/flutter/gestures repository. labels Jan 17, 2026
@dkwingsmt dkwingsmt self-requested a review January 27, 2026 23:25
@dkwingsmt

dkwingsmt commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

I understand the reasoning, but I'm concerned that the API change will probably be breaking. In other words, existing apps that use a nullable type here will get compiler errors. Given how this change is mostly just to make the code pretty, I don't think the breakage can be justified, unfortunately.

Can we still fix the usages without changing the API?

Edit: On another thought, I think being able to support nullable enums is important. How else would you like a class to describe its nullable enum property without this feature? Wrapping the EnumProperty in an if is not the same, since it's more like "this class has this property only occasionally" instead of "this class has this property that allows a null value".

@luanpotter

Copy link
Copy Markdown
Contributor Author

Yeah I wasn't super happy with it in the end. I think my main disagreement with the current structure is that if we want the T? to model nullable enums (seems to be aligned with what you are saying), the value should be of type T. that way the value for nullable enums can be null but it has to be set if the field is non-nullable (which is sound). But I agree this is not worth the trouble - I will just untouch these changes on the main PR.

@luanpotter luanpotter closed this Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: gestures flutter/packages/flutter/gestures repository. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants