eğer veriler 4 saniye içinde gelmezse bir şeyler yapayım istiyorum. nasıl yapabilirim? v


class _RemoteApiKullanimiState extends State<RemoteApiKullanimi> {
  Future<List<Gonderi>> _gonderiGetir() async {
    var response = await http.get("https://jsonplaceholder.typicode.com/posts");
    if(response.statusCode ==200){
     // return Gonderi.fromJsonMap(jsonDecode(response.body)) ;
      return (jsonDecode(response.body)as List).map((teksatirmap)=> Gonderi.fromJsonMap(teksatirmap)).toList();
    }else{
      

    }
  }

opt


try {
  final request = await client.get(...);
  final response = await request.close()
    .timeout(const Duration(seconds: 4));
  // rest of the code
  ...
} on TimeoutException catch (_) {
  // A timeout occurred.
} on SocketException catch (_) {
  // Other exception
}
  • opt replied to this.

    hocam hiç anlamadım else’den sonraya mı yazacağım? ayrıca az çok anlatarak söylerseniz neyin ne olduğunu çok iyi olur

      Flutter hocam elseden sonraki kısımı yazar mısınız eğer mümkünse

      opt Merhaba hocam
      kodu internettn aldım bende
      Siz sorunca biraz daha bakındım.

      
      http.get('url').timeout(
        Duration(seconds: 1),
        onTimeout: () {
          //timeout'a düşerse buradaki kod çalışır.
          return null;
        },
      );

      Sanırım bu işinizi görür

        Write a Reply...