1

Try Set write class on dart like this, but got an error dart(dart_constant_default_value). what happen and what the best way to set default value for DateTime property?

class NewConcern {
  NewConcern({
    required this.name,
    this.description = '',
    this.startDate = DateTime.now(),
    this.endDate = DateTime.now(),
    this.notify = false,
  });

  String name;
  String description;
  DateTime startDate;
  DateTime endDate;
  bool notify;
}
RedBios AS
  • 11
  • 2

2 Answers2

0

it is probably due to the missed @. use @required

Abbasihsn
  • 2,075
  • 1
  • 7
  • 17
0

Try Below code add its work on my machine:

class NewConcern {
  NewConcern({
    this.name,
    this.description,
    this.startDate,
    this.endDate,
    this.notify = false,
  });

  String name;
  String description;
  final DateTime startDate;
  final DateTime endDate;
  bool notify;
}
Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
  • I need setup default value for startDate and endDate with DateTime now, so that property will not have possible to null. – RedBios AS Aug 08 '21 at 08:44