Merhaba ;
şu an aşağıdaki şekilde bir düzenleme yaptım ve servise bağlanıp datayı çektim. ancak bu sefer de map ile ilgili bir hata veriyor.
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
onPressed: () async {
try {
String urL =
'http://192.168.1.118/JsonService.php?I=GirisKontrol&kadi=' +
_usernameController.text +
'&sifre=' +
_passwordController.text;
var reponse = await http.get(Uri.parse(urL));
var response = json.decode(reponse.body);
print(response);
if (response.statusCode == 200) {
var result = welcomeFromJson(response.body);
var girisKontrol = result.data[0].girisKontrol;
if (girisKontrol != "0") {
print('Başarısız !');
} else {
print(result.data[0].adsoyad);
}
} else {
print(response.statusCode);
}
} catch (e) {
print("Hata : " + e.toString());
}
}
Aldığım hata ise aşağıdaki gibidir.
I/flutter ( 7931): {data: [{id: 1, GirisKontrol: 1, adsoyad: Ferhat Bektaş, gsm: 00000, personel: 1, firmaID: 1, yetkiID: 1, birimID: 1, grupno: 3, resim: https://www.sendeoyla.com/assets/img/noavatar.png}]}
I/flutter ( 7931): Hata : NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance getter 'statusCode'.
I/flutter ( 7931): Receiver: _LinkedHashMap len:1
I/flutter ( 7931): Tried calling: statusCode
Map Durumu ise aşağıdaki gibidir.
`import ‘dart:convert’;
Welcome welcomeFromJson(String str) => Welcome.fromJson(json.decode(str));
String welcomeToJson(Welcome data) => json.encode(data.toJson());
class Welcome {
Welcome({
this.data,
});
List<Datum> data;
factory Welcome.fromJson(Map<String, dynamic> json) => Welcome(
data: List<Datum>.from(json[“data”].map((x) => Datum.fromJson(x))),
);
Map<String, dynamic> toJson() => {
“data”: List<dynamic>.from(data.map((x) => x.toJson())),
};
}
class Datum {
Datum({
this.id,
this.girisKontrol,
this.adsoyad,
this.gsm,
this.personel,
this.firmaId,
this.yetkiId,
this.birimId,
this.grupno,
this.resim,
});
String id;
String girisKontrol;
String adsoyad;
String gsm;
String personel;
String firmaId;
String yetkiId;
String birimId;
String grupno;
String resim;
factory Datum.fromJson(Map<String, dynamic> json) => Datum(
id: json[“id”],
girisKontrol: json[“GirisKontrol”],
adsoyad: json[“adsoyad”],
gsm: json[“gsm”],
personel: json[“personel”],
firmaId: json[“firmaID”],
yetkiId: json[“yetkiID”],
birimId: json[“birimID”],
grupno: json[“grupno”],
resim: json[“resim”],
);
Map<String, dynamic> toJson() => {
“id”: id,
“GirisKontrol”: girisKontrol,
“adsoyad”: adsoyad,
“gsm”: gsm,
“personel”: personel,
“firmaID”: firmaId,
“yetkiID”: yetkiId,
“birimID”: birimId,
“grupno”: grupno,
“resim”: resim,
};
}`