-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flutter web - dio bloc's (freezes) ui while getting json response #961
Comments
same problem here |
Same problem. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions. |
This is still an issue in |
This worked for me for the Web bool withCredentials = false; @OverRide
} @OverRide |
Checkout My solution above and I hope it'll work for you too on the web. |
A simpler solution is to understand what 'await' does. The reason your requests are getting queued, is because await explicitly asks that of the framework. the solution would be to use
|
Can anyone confirm this? |
Same problem here |
I'm still having this problem on flutter web. Any solutions? |
Same problem here |
same problem here , it taking 3 to 4 second to load data, |
Salam @altafkhan8719 `import 'dart:async'; class WebClientAdapter implements HttpClientAdapter { bool withCredentials = false; @OverRide
} @OverRide if (kIsWeb) { ---------------------> dio.httpClientAdapter = WebClientAdapter(); } }` |
same error |
Is that web only issue? On Android/iOS I don't get any difference, both default http client and dio give the same load time and no freezes. I use dio to make simple rest calls, but response may be large in some cases. Overall, response and load time is similar to default http client and native Android OkHttp with gson. |
@giaur500 I just quickly checked with Android on the same endpoint/dataset - it seems it happens there too. Not as badly as for web - ~1.5 sec complete UI freeze (Android) vs 15 sec freeze on web. But freeze still happens. Just not noticeable on smaller datasets in comparison to web, I suppose. |
Do you use isolates (flutter compute) to parse json? I see no freezes and response size is ~400 kB. Dio version 4.0.0, but 3.10 was ok too as far as I remember. GET request call +parse + finally appear result in gui takes approx 0.5 to max 1 second. On native Android it's not better. Other thing that can make difference - http compression is enabled on server. |
No isolates. Just Retrofit + Dio. My response is 1.5 MB in size, could it make difference? there is an "update in progress" spinner in appbar of my app, so it is clearly visible:
simply replacing Retrofit/Dio call to HTTP client one + manual obj.fromJson(...) - gets same 5-7 secs timing for the network but no any freeze then. The timing for obj.fromJson(jsonDecode(...)) for this payload is only 157 ms so it seems this functional transformation of the request body "eats" the main thread (even if run in isolate) and this most noticeably affects web targets. Dunno whether this is a language/compiler or flutter issue or not. |
Try to use Dio (without Retrofit) to see what happens. Also, you should notice Dio has its defualt transformer for json, maybe it causes freezes? I use raw response this way: |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions. |
Hi guys, I'm also interested in this particular subject. Making a request with Dio on Flutter Web freezes completely the UI. After 2 days without any elegant solution to the problem, decided to switch request client for certain api calls with http. Literally no issues when switching. Has anyone come up with a solution? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions. |
Still having this in the latest version of dio (4.0.0). I tried using an isolate to do the json_decode but still a good bit of jank after the response comes in. If needed I can provide a test project to simulate this behaviour. Anyone else got a viable solution to the problem? |
@Mooibroek unfortunatelly the only work around at least for me was to make request with different client for web, mobile works good, but probably will finally migrate all to only one request client in order not to have extra logic by using 2 clients. :( |
I've got the problem on macos now, ill try the mobile and see how that goes. |
Just FYI - we completely abandoned both DIO and Retrofit due to that. |
@maares mobile works faster (probably due to native code) but is affected by the same issue - the lag is just much smaller in comparison to the web. So, IMO, no need to use 2 clients, just move away from DIO/Retrofit. As I mentioned above - standard HTTP package syntax is quite nice and simple, still flexible |
Yeah lag on mobile is also there, but less then on macos. Shame really. For now its not a deal breaker for this project, but definitely something to take into account for new projects in the future. |
How do you use basic http client on web? In my case no matter what I do, I'm getting exception "Unsupported operation: Platform._version", even if I do what they suggested, exception is still there. |
This is the direct snippet from our app, just anonymized sensitive data.
|
@livotov thanks for actually observing lag is on mobile as well, honestly I did not notice on Mobile. A shame, this was actually one of the first packages I installed when starting playing around with flutter. Hopefully at some point this will be addressed |
Hi all. Perhaps for some this is still relevant. I had the same problem - the interface froze when there were heavy replies. My problem was that I had a log interceptor that was writing a lot of data to the console. Check if you have the same interceptors or just print(some data) with a large amount of data. This could be one of the problems. |
I encountered a similar issue, but I managed to solve it by simply adding validateStatus to my Dio configuration: Dio(BaseOptions(
baseUrl: Urls.base,
headers: {
'Content-Type': 'application/json',
},
connectTimeout: const Duration(seconds: 2),
receiveTimeout: const Duration(seconds: 2),
validateStatus: (status) => status! >= 200 && status < 500,
)); With |
Using default flutter project simple dio.get freezes CircularProgressIndicator while receiving response.
Tested first on iphone and ipad, works fine.
Then converted project to flutter web.
//code
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@OverRide
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State {
int _counter = 1;
void _incrementCounter() async {
}
@OverRide
Widget build(BuildContext context) {
}
_presentProgress() {
if (_counter % 2 == 0){
return CircularProgressIndicator();
}else{
return Text('Press (+) to send Api request');
}
}
}
The text was updated successfully, but these errors were encountered: