class Product {
int id;
String name;
String description;
double unitPrice;
Product(this.id, this.name, this.description, this.unitPrice);
Product.withId(this.id, this.name, this.description, this.unitPrice);
Future<Map<String, dynamic>> toMap() async {
var map = <String, dynamic>{};
map["name"] = name;
map["description"] = description;
map["unitPrice"] = unitPrice;
map["id"] = id;
}
Product.fromObject(dynamic o){
id = int.tryParse(o["id"])!;
name = o["name"];
description = o["description"];
unitPrice = double.tryParse(o["unitPrice"])!;
}
}
Getting an error like this:
The body might complete normally, causing 'null' to be returned, but the return type, 'FutureOr<Map<String, dynamic>>', is a potentially non-nullable type.
Non-nullable instance field 'description' must be initialized.
Non-nullable instance field 'id' must be initialized.
Non-nullable instance field 'name' must be initialized.
Non-nullable instance field 'unitPrice' must be initialized.