Search code examples
flutterdio

How to know the time period server response in the Dio library?


How to know the time period server response in the Dio library?

I use postman, it returns status, time period, size of the response, ...

enter image description here

How to get values in Dio lib? (I need it to write log)


Solution

  • You could use a stop watch to measure how much the request took

    var stopWatch = Stopwatch();
        
    stopWatch.start();
    performReques();
    stopWatch.stop();
    
    // convert the duration to string
    var elapsedString = stopWatch.elapsed.toString();
    
    // or just get duration in seconds
    var elapsedSeconds = stopWatch.elapsed.inSeconds;