A value of type ‘Color?’ can’t be assigned to a variable of type ‘Color’

Trying to pass a default value for background color to the constructor but these are the error messages popping up. I have tried using Colors.red[200]! and Colors.red.shade200 but none of those worked out.

import "package:flutter/material.dart";

class Category {
  final String id;
  final Color bgColor;
  final String title;

  Category(
    {required this.id, required this.title, this.bgColor = Colors.red[200]});
}

enter image description here



Read more here: https://stackoverflow.com/questions/68464385/a-value-of-type-color-cant-be-assigned-to-a-variable-of-type-color

Content Attribution

This content was originally published by Manraj Singh at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: