well i have a little problem with the listview builder , i make a request on a api and i am upposed to display the result depending on the length of the result, it works very well but when i have no data from the api, i have this message from flutter : no suchMethosError:"map" Dynamic call with incorrect number of type arguments Expected 2 actual 1 Receiver instance of 'jsonMap' Arguments:[instance of dynamic)=> historique]
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:tentative_formulaire_konamicash/pages/post_history.dart';
import 'package:tentative_formulaire_konamicash/pages/test_vfetch.dart';
class gamehistory extends StatefulWidget {
const gamehistory({
super.key,
required this.email,
required this.password,
});
final String password;
final String email;
@override
State<gamehistory> createState() => _gamehistoryState();
}
class _gamehistoryState extends State<gamehistory> {
Future<void> equipe(String lepgagnant) async {
var url = Uri.parse('https://konamicash.com/jeux_app');
var response = await http.post(url, headers: {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*"
}, body: {
"email": widget.email,
});
if (response.statusCode == 200) {
var retour = jsonDecode(response.body);
print(retour);
setState(() {});
}
}
Future<void> contenu() async {
var url = Uri.parse('https://konamicash.com/vfetch_app');
var response = await http.post(url, headers: {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*"
}, body: {
"email": widget.email,
});
if (response.statusCode == 200) {
var reponse = jsonDecode(response.body);
if (reponse['situation'] == 0) {
print('no data');
} else {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) =>
TestVfetch(mail: widget.email, password: widget.password),
transitionsBuilder:
(context, animation, secondaryAnimation, child) {
animation =
CurvedAnimation(parent: animation, curve: Curves.ease);
return FadeTransition(
opacity: animation,
child: child,
);
}),
);
}
print(reponse);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('message'),
),
);
}
}
late Future<List<history>> usersFuture = vfetchdata();
Future<List<history>> vfetchdata() async {
final url = Uri.parse('https://konamicash.com/jeux_app');
final response = await http.post(url, headers: {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*"
}, body: {
"email": widget.email,
});
final body = json.decode(response.body);
return body.map<history>(history.fromJson).toList();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('konami'),
),
body: Center(
child: FutureBuilder<List<history>>(
future: usersFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.hasData) {
final users = snapshot.data!;
return buildstories(users);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
} else {
return const Text('nothing to display');
}
}),
),
);
}
}
Widget buildstories(List<history> users) => ListView.builder(
itemCount: users.length,
itemBuilder: (context, index) {
final user = users[index];
return Card(
child: ListTile(
leading: CircleAvatar(
backgroundImage:
NetworkImage('https://konamicash.com/${user.image_equipe}'),
),
title: Text('${user.name} ${user.mail}'),
subtitle: Text(user.phone),
),
);
});
//My class history
class history {
final String name;
final String mail;
final String phone;
final String cote;
const history(
{required this.name,
required this.mail,
required this.phone,
});
static history fromJson(json) => history(
nom: json['name'],
prenoms: json['mail'],
numero_de_telephone: json['phone'],
);
}