I am learning Flutter and GetX. I have got Model:
class SectionsDBStat {
int notificationsTotalCount;
int notificationsWaitingForProcessing;
DateTime notificationsLastArchiveDate;
SectionsDBStat({
required this.notificationsTotalCount,
required this.notificationsWaitingForProcessing,
required this.notificationsLastArchiveDate
});
factory SectionsDBStat.fromJson(Map<String, dynamic> json) {
return SectionsDBStat(
notificationsTotalCount: json['notificationsTotalCount'],
notificationsWaitingForProcessing: json['notificationsWaitingForProcessing'],
notificationsLastArchiveDate: DateTime.parse(json['notificationsLastArchiveDate'])
);
}
}
I am trying to create Getx contoller that receive data from http:
class SectionsStatController extends GetxController {
SectionsDBStat sectionsDBStat = Future.value(<SectionsDBStat>).obs;
getStat() async {
var value = await http.get('${url}/stat?total');
if(value.statusCode == 200) {
Map<String, dynamic> valueMap = jsonDecode(value.body)['data'];
sectionsDBStat = SectionsDBStat.fromJson(valueMap);
update();
} else {
print("Can't get stat: ${value.statusCode}");
}
}
}
I am getting an error:
A value of type 'Rx<Future<List<SectionsDBStat>>*>*' can't be assigned to a variable of type 'SectionsDBStat'.
So I should use another type. But what? I tried final
but got error:
'sectionsDBStat' can't be used as a setter because it's final.