I'm developing a country-city-like system. I'm pulling the data with json via phpmyadmin. but even if the system is working, it crashes from time to time.
Padding(
padding: const EdgeInsets.only(left: 20, right: 20),
child: DropdownButton(
dropdownColor: Colors.white,
value: selectedfakId,
hint: Text("Fakülte Seçin"),
items: datafak?.map((faklist) {
return new DropdownMenuItem(
child: Text(faklist["name"]),
value: faklist["fakulte_id"],
);
}).toList() ??[],
onChanged: (value) {
setState(() {
selectedfakId = value as String?;
});
},
Future fakliste() async {
var url = "https://www.forumuni.com/forumunimob/unilist.php?send=faklist";
// ignore: unused_local_variable
var response = await http.post(Uri.parse(url),
body: {"uniid": selectedId}, headers: {"Accept": "application/json"});
var jsonbody = response.body;
var jsondata = json.decode(jsonbody);
setState(() {
datafak = jsondata;
});
// ignore: avoid_print
print(jsondata);
return "success";
}
PHP code:
$list = array();
$uniid = $_POST["uniid"];
$fak = $conn->query("SELECT * FROM table WHERE id = '$uniid' ORDER BY name");
while($faklist = $fak->fetch(PDO::FETCH_ASSOC))
{
$list[] = $faklist;
}
if($uniid != null)
{
echo json_encode($list);
}
else
{
echo json_encode("a");
}
Error
CodePudding user response:
You are getting this error because faklist["fakulte_id"]
of every item is not unique
, two or more values of fakulate_id
is same. Where as value
in DropDownButton
needs unique value for every item.
Make sure fakulte_id
is unique, else you need to change the value
to something which has unique value for every item in DropDownButton
.