I tried to do the sum by taking the model that I had made but the results were like.
has anyone ever had a similar case and how to solve it.
this is the function that I made to do the addition with the type
String parameter because in the API the data type is string.
totalCalculate<NilaiMahasiswa>(nilaiAkhirUas, String nilaiIndeksAkhir) {
int nilaiAkhirUas = int.parse(["nilay_akhir_uas"]!);
double nilaiIndeksAkhir = double.parse(["nilay_akhir"]!);
return nilaiAkhirUas + nilaiIndeksAkhir;
}
and this is when I call the result of the sum above or in the function above but an error occurs
Flexible(
child: FutureBuilder<NilaiMahasiswa>(
future: Services().getNilaiMahasiswa(semester),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text(
// 'IPK ${snapshot.data!.data?.first.updatedBy}',
'IPK $totalCalculate',
style: bold5,
);
} else if (snapshot.hasError) {
print(snapshot.data);
return Text('${snapshot.error}');
}
return const CircularProgressIndicator();
},
),
),
and this is the error message that is displayed
3
Answers
int.parse
expectsString
notList of String
so,Should work
You are trying to parse int from List
int.parse(["nilay_akhir_uas"]!)
. Actually this will raise error. Maybe you just like to read the map, I guess the map isnilaiAkhirUas
. So it is safe to.tryParse
Or if those parameters are string, you can do
maybe you wanted to do this: