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


Im using this package

flutter_datetime_picker: ^1.5.1

And this is my code

String _date  "Please pick Age";

  Widget _buildage() {
    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        'Enter Age',
        style: kLabelStyle,
      SizedBox(height: 10.0),
        decoration: kBoxDecorationStyle,
        alignment: Alignment.centerLeft,
        height: 70.0,
        child: Container(
          child: TextFormField(
            initialValue: "haaas",
            validator: (val) {
              if (val.isEmpty) {
                return 'Enter yout Age';
              if (val.length < 4) {
                return 'Enter a username minimun 4 chars long';

              return null;
            onChanged: (val) {
              setState(() > age  val);
            onTap: () {
                  theme: DatePickerTheme(
                    containerHeight: 210.0,
                  showTitleActions: true,
                  minTime: DateTime(2000, 1, 1),
                  maxTime: DateTime(2022, 12, 31), onConfirm: (date) {
                setState(() {
                  _date  '${date.year} - ${date.month} - ${date.day}';
              }, currentTime: DateTime.now(), locale: LocaleType.en);
            readOnly: true,
            decoration: InputDecoration(
              border: InputBorder.none,
              contentPadding: EdgeInsets.only(top: 14.0),
              prefixIcon: Icon(
                color: Colors.white,
                size: 28,
              hintText: " $_date",
              hintStyle: kHintTextStyle,

the error or warning is this

../../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_datetime_picker-1.5.1/lib/flutter_datetime_picker.dart:311:32: Warning: Operand of null-aware operation '??' has type 'Color' which excludes null.
 - 'Color' is from 'dart:ui'.
                  color: theme.backgroundColor ?? Colors.white,

Everything works fine and I dont know why im getting this error . if you need more information please leave a comment. Hope anyone knows how to fix that . If you need any other information please leave also a comment


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.

Answered By – Abion47

Leave a Comment