-
Notifications
You must be signed in to change notification settings - Fork 28.6k
MaterialStateColor.resolveWith
cannot return null
value.
#116590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc: @HansMuller |
MaterialStateColor.resolveWith
cannot return null
value even when property is nullable. MaterialStateColor.resolveWith
cannot return null
value.
Sorry, that's wrong. A MaterialStateColor is-a Color, so its resolve method can't return null. But I believe that the places where we're returning Colors.transparent by default are intentional, to distinguish a situation where no fill color is desired vs "use the default fill color". |
Yeah the main use of transparent was to indicate that you didn't want a color for something that had a default. Trying to use null for that case doesn't work, as it is used to indicate that you want the default, not that you don't want any color. The main example of this is with As for the issue at hand here, as Hans pointed out, it wouldn't make sense for |
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 |
Uh oh!
There was an error while loading. Please reload this page.
I've come across this in previous PRs and in a recent PR.
Take this as an example where
Color? get selectedColor
is nullable butMaterialStateColor.resolveWith
doesn't allow returning a null value.In a case where we need to return a
null
so an "effectiveColor" variable can fall back to a different color for the default property.I would have to provide a condition to avoid getting
Colors.transparent
, like this.I've noticed this pattern throughout the framework where
MaterialStateColor.resolveWith
often resorts toColors.transparent
. I would like to make sure this doesn't go unnoticed if it is by design and if there is a way to returnnull
.Here are some instances:
flutter/packages/flutter/lib/src/material/menu_anchor.dart
Lines 3712 to 3719 in 921f077
flutter/packages/flutter/lib/src/material/checkbox.dart
Lines 844 to 856 in 921f077
flutter/packages/flutter/lib/src/material/slider.dart
Lines 1938 to 1950 in 921f077
The text was updated successfully, but these errors were encountered: