Добрый день, начал проходить курс ао языку Dart и встретился с следующей проблемой.
Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
bin/class.dart:16
this.fuel Capacity = double.parse(map["fuel Capacity"]);
Я вроде как изменил тип данных но он всё ровно выдает ошибку.
class Vehicle {
var manufacturer;
var fuelCapacity;
var fuelRemaining;
String showInfo() =>
"$manufacturer: $fuelRemaining fo $fuelCapacity (critical: $criticalFuelLevel)";
double get criticalFuelLevel => fuelRemaining * 0.1;
set newFuelRemaining(double val) => fuelRemaining = val;
Vehicle({this.manufacturer, this.fuelCapacity, this.fuelRemaining});
Vehicle.fromMap(Map<String, String> map) {
this.fuelRemaining = map["fuelRemaining"];
this.fuelCapacity = double.parse(map["fuelCapacity"]);
this.fuelRemaining = double.parse(map["fuelRemaining"]);
}
}
void main() {
var vehicle =
Vehicle(manufacturer: "BMW", fuelCapacity: 55, fuelRemaining: 32);
vehicle.newFuelRemaining = 20;
var vehicle2 = Vehicle.fromMap(
{"fuelRemaining": "dsd", "fuelCapacity": "50", "fuelRemaining": "32"});
print(vehicle2.showInfo());
print(vehicle.showInfo());
}