jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.24k stars 1.61k forks source link

GetConnect Timeout Still not work #1798

Open gushendra86 opened 3 years ago

gushendra86 commented 3 years ago

Hello,

I think it still have a bug at GetConnect when using timeout on get 4.3.8.

i write this code on base_provider.dart

import 'package:get/get_connect/connect.dart';

class BaseProvider extends GetConnect {
  @override
  void onInit() {
    httpClient.defaultContentType = "multipart/form-data";
    httpClient.timeout = Duration(seconds: 2);

    super.onInit();
  }
}

And then on UserProvider i write this :

import 'dart:async';

import 'package:get/get.dart';
import 'package:myget/providers/base_provider.dart';

class UserProvider extends BaseProvider {
  final url = 'http://192.168.0.4/student/api';
  final sessionid = '5f0e6bfbafe255.00218389';

  // add user
  Future<Response> postData(String name, String email, String phone) async {
    final postData = FormData({
      'session_id': sessionid,
      'student_name': name,
      'student_phone_number': phone,
      'student_gender': 'male',
      'student_address': email
    });

    var response = await post(url+'/student/addStudent', postData);

    print(response.body.toString());

    return response;
  }
}

There are 2 error :

  1. On my PHP API file, i add code sleep(4); So the API will be called after 4 second, and then in the application i set the timeout is 2 second. I still get the result from API and timeout is not affect.
  2. Another error is when i don't set the timeout from the onInit(). And then on the PHP API file, i add code sleep(7); After that when i call function postData, there are no result. This error is not happen when i use get 4.1.4, but the error happen at get 4.3.8

And is there a callback when the timeout is triggered ? For example i want to show toast and close progress dialog when the http request is timeout.

Thank you and kind regards

gorkemsari commented 3 years ago

@jonataslaw hi, any updates?

@gushendra86 i use temporary solution like below.

try {
      var response = await post(url+'/student/addStudent', postData).timeout(
        Duration(seconds: 5)
      );
    } on TimeoutException catch (_) {
      // catch timeout here..
    } catch (e) {
      // error
    }
mathiuleo commented 3 years ago

Hello,

Is there any updates for getConnect ? @jonataslaw

Thanks

jasonlaw commented 3 years ago

Just a quick check, did you injected the dependency with Get.put or Get.lazyPut?

894

mathiuleo commented 3 years ago

For me, i am using Get.lazyPut in the Bindings.

LukeStanyer commented 2 years ago

For me, this issue was caused by having the Controller before the Provider in the Binding.

Putting Provider first fixed this issue for me, as below:

class MyBinding extends Bindings {
  @override
  void dependencies() {
    Get.lazyPut<MyProvider>(
      () => MyProvider(),
    );
    Get.lazyPut<MyController>(
      () => MyController(),
    );
  }
}

and then in your provider call, get, post etc on httpClient

httpClient.get(
      'home',
    );`
Technogeekpro commented 2 years ago

Still not working for me @LukeStanyer

astheras commented 2 years ago

the same here. it's urgent, please...

ardipermana59 commented 2 years ago

@astheras alternatively you can manually call onInit(); but of course this is not the best way

astheras commented 2 years ago

i already have this

  @override
  void onInit() {
    httpClient.timeout = const Duration(seconds: 60);
    super.onInit();
  }

but it doesn't work

inyong1 commented 2 years ago

I gues the current timeout setting is only for connecting timeout. Not for receiving data timeout. If we sleep the process on the server will not take effects. Because the connection already connected before timeout reached.

I hope willbe more timeout setting in getConnect. Separated setting for connecting timeout, and receiving data timeout

RuanBonavina commented 2 years ago

I had the same problem, i solved it setting the timeout in my class:

RestClient extends GetConnect  {
  RestClient() {
    baseUrl = "my-url";
    timeout = const Duration(seconds: 30);
    maxAuthRetries = 3;
  }
}
sclausen commented 1 year ago

I had the same problem, i solved it setting the timeout in my class:

RestClient extends GetConnect  {
  RestClient() {
    baseUrl = "my-url";
    timeout = const Duration(seconds: 30);
    maxAuthRetries = 3;
  }
}

Flutter beginner here to the downvoters: What's wrong with this approach?

ghenry commented 1 year ago

I had the same problem, i solved it setting the timeout in my class:

RestClient extends GetConnect  {
  RestClient() {
    baseUrl = "my-url";
    timeout = const Duration(seconds: 30);
    maxAuthRetries = 3;
  }
}

Flutter beginner here to the downvoters: What's wrong with this approach?

Hi Sebastian,

For me personally, this is far to long for an app. Is a user really going to wait more than say, 2 secs vs 1 and a half mins?

Have a listen to this https://www.se-radio.net/2020/09/episode-428-matt-lacey-on-mobile-app-usability/ and enjoy reading this excellent book https://www.manning.com/books/usability-matters

Both talk about design patterns and UX.

sclausen commented 1 year ago

Ah, I see! It’s the value you’ve something against, not the form. I don’t want to judge the value, since I don’t know the particular usecase. 😅

dathdq-imt commented 11 months ago

Hi @gushendra86 @jasonlaw Has this bug been closed yet?