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,
};
}`

pluscoder aşağıdaki şekilde bir girişimim oldu ama başarılı olamadım.

Servisten dönen cevabı paylaşabilir misiniz ?

    2 months later

    pluscoder
    hatanın sebebi şu
    response.statusCode == 200
    bu kısmı
    reponse.statusCode == 200
    olarak değiştir. Bu şekilde kullandığın yerleri değiştirirsen sorun gidecektir.
    response değişkeni json.decode(reponse.body) tutuyor. status code body’de değil. get metodunun döndüğü response’da tutuluyor.

    Merhaba ;

    evet orayı atlamışım ama sorun ordan da kaynaklı değil. düzenlemeyi yaptım json ve map doğru response.body yi ekrana print edebilyorum ama json a convert ederken aşağıdaki hatayı alıyorum.

    NoSuchMethodError: Class ‘_InternalLinkedHashMap<String, dynamic>’ has no instance getter ‘body’.

    var reponse = await http.get(Uri.parse(urL));
    var response = json.decode(reponse.body);
    print(response);

    bu işlemde print ettiği değer : {data: [{id: 0, GirisKontrol: 0, adsoyad: , gsm: , personel: , firmaID: 0, yetkiID: 0, birimID: 0, grupno: 0, resim: }]}

    Aşağıdaki işlemde print(result) dediğimde ise NoSuchMethodError: Class ‘_InternalLinkedHashMap<String, dynamic>’ has no instance getter ‘body’. bu hatayı veriyor.

    var reponse = await http.get(Uri.parse(urL));
    var response = json.decode(reponse.body);
           
            if (reponse.statusCode == 200) {
              var result = welcomeFromJson(response.body);
              **print(result);**
              var girisKontrol = result.data[0].girisKontrol;
    
              if (girisKontrol != "0") {
                print('Başarısız !');
              } else {
                print(result.data[0].adsoyad);
              }
            } else {
              print(response.statusCode);
            }

    konuyla ilgili şöyle bir yazı buldum ama nasıl bir değişiklikten bahsettiğini tam anlamadım.

    https://stackoverflow.com/questions/54344420/flutter-internallinkedhashmapstring-dynamic-has-no-instance-method-cast-w

      biraz kurcaladım ve aşağıdaki şekilde çözdüm arkadaşlar.
      hatam şuymuş, zaten burda gelen body yi json a çevirip bir de var result = welcomeFromJson(response.body); burda bir convert işlemi yapmaya çalışırken hata veriyormuş. üstteki jsona convert olayını devre dışı bıraktım,

      var result = welcomeFromJson(reponse.body);

      burayı da bu şekilde düzenledim.
      var reponse = await http.get(Uri.parse(urL));
      //var response = json.decode(reponse.body);

        yeni sorum şu (:

        şimdi giriş yaptım sisteme ben, karşılığında bir oturumID ve kullanıcı adı gibi değerlerim var ve bunları projemin tamamında kullanabileceğim session gibi bir değişkene aktarmak istiyorum.

        nasıl yapabilirim?

        2 months later

        pluscoder Merhaba.
        Arkadaşın verdiği örnek gibi localStorage kullanılması bence şart diğer türlü işlem yaparsınız ama sayfalar arası geçiş lerde bile sorun yasayabilirsiniz.

          Write a Reply...