Why im getting this error Warning: Operand of null-aware operation ‘??’ has type ‘Color’ which excludes null

That’s not an error, it’s a warning coming from the flutter_datetime_picker package that indicates it hasn’t quite updated its code to be fully idiomatic with null safety. Basically, it’s using the ?? operator on the off-chance that theme.backgroundColor is null, but now that theme.backgroundColor is marked as non-nullable, the operator is redundant. It’s annoying to have the warning pop up, but it won’t affect your app in any way.

Note that the code has been properly updated in the master branch of the package repository, so the next time the package is published, the warning will disappear.

EDIT: As of version 1.5.1, this package now officially supports null safety. The fix was added via pull request after 1.5.1’s release, so the next version (1.5.2 or something) should address this issue.

EDIT 2: Coming up on a year since the last commit and 14 months since 1.5.1 was published, it’s probably safe to assume this package has been abandoned. It’s worth noting that, apart from specific functionality that I am not aware of, CupertinoDatePicker in the built-in Flutter library now renders this package obsolete anyway.

For those who for whatever reason want to continue using this package without the warning, you can change the package dependency to point to the master branch of the repository (credit [1] [2]):

flutter_datetime_picker:
    git:
      url: https://github.com/AlexHartford/flutter_datetime_picker.git
      ref: master

It’s worth noting that this approach could expose your app to breaking changes if the package developer comes back with new commits, as well as vulnerabilities if the repository becomes the target of malicious activity. You would also lose the benefits of using the pub package manager, such as version management and automatic upgrades. As such, I would highly recommend anyone still using this package to migrate to Flutter’s CupertinoDatePicker above.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)