I made a class notification to initialise my data, but when I call it in my future function it shows me an error.
Future <List<Notification>> _getNotification() async {
var data = await http.get("$baseUrl/efficience001_webservice/notification.php");
var jsonData = json.decode(data.body);
List<Notification> notifs = [];
for (var u in jsonData){
Notification notif = Notification(u["description"],u["nom_ligne"], u["created_at"]);
notifs.add(notif);
}
print(notifs.length);
return notifs;
}
class Notification {
final String description;
final String nom_ligne;
final DateTime created_at;
const Notification({this.description, this.nom_ligne, this.created_at});
}
error: Too many positional arguments , 0 expected, but 3 found.
The problem here is that you are using named parameters for your Notification
class but pass positional parameters.
You have two options to solve it:
Notification
class to:const Notification(this.description, this.nom_ligne, this.created_at);
Notification
class. In order to do this, change one line in your for
-loop:Notification notif =
Notification(description: u["description"], nom_ligne: u["nom_ligne"], created_at: u["created_at"]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With