Reputation: 305
I am trying to do a computation. But my value is from a int?
and it not letting me to do it. the error is The argument type 'int?' can't be assigned to the parameter type 'num'.
I don't understand.
Here is my code:
String goal= "1000";
String workout = "0";
String remaining = "";
int? _total;
@override
void initState() {
super.initState();
dbHelper = DbHelper();
_calcTotal();
}
void _calcTotal() async{
var total = (await dbHelper.calcTotal())[0]['total'];
print(total);
setState(() => _total = total);
}
int resulttext = int.parse(goal) - _total + int.parse(workout);
remaining = resulttext.toString();
Upvotes: 6
Views: 29313
Reputation: 29
**int amt = 0;
amt = int.tryParse(widget.price)!;
setState(() {
_increment();
sum = sum + amt;
});
in this code widget.price comes from previcious widgets and price is actually stored in a Firebase as a string so then i convert into int first and assign a new variable i works for me**
Upvotes: 0
Reputation: 371
setState(() {
sliderlength = _carouselImages!.length;
});
This will fix your problem .
Upvotes: 3
Reputation: 305
I solved my problem by this. I just add this line:
var total = _total?.toInt() ?? 0;
before this:
int resulttext = int.parse(goal) - (total + int.parse(workout));
Upvotes: 12