我有一个像这样的情况,但我不明白为什么会发生这种情况,因为控制台没有错误信息。
我想对API中的数据进行求和,但输出结果如下。
这里我进行求和操作
int getSum() {
int? uts = int.tryParse(data.first.nilaiIndeksUts ?? '');
int? akhir = int.tryParse(data.first.nilaiIndeksAkhir ?? '');
return (uts ?? 0) + (akhir ?? 0);
}
我在这里调用了getSum函数
Text(
'$getSum',
style: bold6,
),
这是我从API中制作的模型,我已经找了几天还没有找到解决方案。 这里有没有人遇到过类似的情况或者在API中做过数据汇总? 提前感谢。
class NilaiMahasiswa {
String? status;
String? code;
List<Data>? data;
NilaiMahasiswa({this.status, this.code, this.data});
NilaiMahasiswa.fromJson(Map<String, dynamic> json) {
status = json['status'];
code = json['code'];
if (json['data'] != null) {
data = <Data>[];
json['data'].forEach((v) {
data!.add(Data.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['status'] = status;
data['code'] = code;
if (this.data != null) {
data['data'] = this.data!.map((v) => v.toJson()).toList();
}
return data;
}
}
class Data {
String? idTranskripNilai;
String? idMk;
String? kodeMk;
String? nmMk;
int? sks;
int? smt;
String? nilaiAkhirUts;
String? nilaiHurufUts;
String? nilaiIndeksUts;
String? nilaiAkhirUas;
String? nilaiAkhir;
String? nilaiHurufAkhir;
String? nilaiIndeksAkhir;
int? statusNilaiAkhir;
int? statusNilaiUts;
String? updatedBy;
Data(
{this.idTranskripNilai,
this.idMk,
this.kodeMk,
this.nmMk,
this.sks,
this.smt,
this.nilaiAkhirUts,
this.nilaiHurufUts,
this.nilaiIndeksUts,
this.nilaiAkhirUas,
this.nilaiAkhir,
this.nilaiHurufAkhir,
this.nilaiIndeksAkhir,
this.statusNilaiAkhir,
this.statusNilaiUts,
this.updatedBy});
Data.fromJson(Map<String, dynamic> json) {
idTranskripNilai = json['id_transkrip_nilai'];
idMk = json['id_mk'];
kodeMk = json['kode_mk'];
nmMk = json['nm_mk'];
sks = json['sks'];
smt = json['smt'];
nilaiAkhirUts = json['nilai_akhir_uts'];
nilaiHurufUts = json['nilai_huruf_uts'];
nilaiIndeksUts = json['nilai_indeks_uts'];
nilaiAkhirUas = json['nilai_akhir_uas'];
nilaiAkhir = json['nilai_akhir'];
nilaiHurufAkhir = json['nilai_huruf_akhir'];
nilaiIndeksAkhir = json['nilai_indeks_akhir'];
statusNilaiAkhir = json['status_nilai_akhir'];
statusNilaiUts = json['status_nilai_uts'];
updatedBy = json['updated_by'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id_transkrip_nilai'] = idTranskripNilai;
data['id_mk'] = idMk;
data['kode_mk'] = kodeMk;
data['nm_mk'] = nmMk;
data['sks'] = sks;
data['smt'] = smt;
data['nilai_akhir_uts'] = nilaiAkhirUts;
data['nilai_huruf_uts'] = nilaiHurufUts;
data['nilai_indeks_uts'] = nilaiIndeksUts;
data['nilai_akhir_uas'] = nilaiAkhirUas;
data['nilai_akhir'] = nilaiAkhir;
data['nilai_huruf_akhir'] = nilaiHurufAkhir;
data['nilai_indeks_akhir'] = nilaiIndeksAkhir;
data['status_nilai_akhir'] = statusNilaiAkhir;
data['status_nilai_uts'] = statusNilaiUts;
data['updated_by'] = updatedBy;
return data;
}
}
getSum
。 - hobbs