Help me please... I tried to solve this problem since some days but nothing worked T.T
I have a DB phpmyadmin
I want to show a list from json delivered by a php url. I tried to adapt this code, https://www.fluttercampus.com/guide/53/how-to-make-drop-down-and-insert-options-by-php-mysql-in-flutter/ but I have this error
The following NoSuchMethodError was thrown building AddTimePage(dirty, dependencies: [MediaQuery], state: AddTimeState#1a618): The method '[]' was called on null. Receiver: null Tried calling:
I don't understand what is null or [] ... The json I received is OK
My function to get data
Future<dynamic> getTypeTemps() async {
var res = await http.post(Uri.parse(TTurl + "?action=LST"));
if (res.statusCode == 200) {
setState(() {
TTdata = json.decode(res.body);
});
} else {
setState(() {error = true; message = "Erreur avec la table TypeTemps";});
} }
getTypeTemps is called in void initstate()
The widget to show the list
Widget WdgListTT() {
List<TypesTemps> ttlist = List<TypesTemps>.from(
TTdata["TTdata"].map((i){
return TypesTemps.fromJSON(i);
})
); //searilize typetemps json data to object model.
return Column(children: [
const Padding(
padding: EdgeInsets.only(bottom: 20),
),
SizedBox(
width: MediaQuery.of(context).size.width - 40,
child: const Text("Type de temps", style: TextStyle(color: Colors.teal, fontWeight: FontWeight.bold, fontSize: 18),),
),
SizedBox(
width: MediaQuery.of(context).size.width - 50,
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
//style: const TextStyle(color: Colors.white),
value: valtypetemps,
onChanged: (value) => setState(() => valtypetemps = value),
elevation: 20,
underline: Container(
height: 10,
color: Colors.red,
),
hint: const Text("Sélectionnez un type",
style: TextStyle(fontSize: 16)),
isExpanded: true,
items: ttlist.map((typesTemps) {
return DropdownMenuItem(
child: Text(typesTemps.libelle,
style: TextStyle(color: Colors.black)),
value: typesTemps.libelle,
);
}).toList(),
)))
]); }
The class
class TypesTemps { String code, libelle, type_temps; TypesTemps({
required this.code,
required this.libelle,
required this.type_temps, }); factory TypesTemps.fromJSON(Map json) {
return TypesTemps(
code: json["CODE"],
libelle: json["LIBELLE"],
type_temps: json["SENS_TYPE_TEMPS"]); } }