Home > Blockchain >  Non-nullable instance field 'day' must be initialized
Non-nullable instance field 'day' must be initialized

Time:01-19

Try adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'

This is my code:

class _DayViewState extends State<DayView> {
  List<charts.Series<TaskData, int>> listOfTasks;
  Map<int, String> days = new Map();
  int day;

  _DayViewState(List<charts.Series<TaskData, int>> list, int day) {
    this.listOfTasks = list;
    this.day = day;
  }

  setIt() {
    setState() {
      build(context);
    }
  }

CodePudding user response:

You can include late keyword as error message suggested.

class _DayViewState extends State<DayView> {
  late List<charts.Series<TaskData, int>> listOfTasks;
  Map<int, String> days = new Map();
  late int day;

Can also be nullable or you can just do

_DayViewState(this.listOfTasks, this.day);

Find more about null-safety

  • Related