Closed
Description
In my application, the SDK used before was 1.9 and everything worked fine. After upgrading to 1.12, android still works well, but ios will get stuck on the splash screen.
Detailed questions:
- Sometimes the first time you start it will get stuck on the splash screen.
- Manually kill the process and then enter the app, there is a high possibility that it will get stuck on the splash screen page.
Code situation
- pubspec.yaml
http: 0.12.0+4 - lib/SplashPage.dart
class SplashPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _StdPageState();
}
}
class _StdPageState extends State<SplashPage> {
@override
void initState() {
super.initState();
// send Http here
}
}
- lib/util/HttpsUtils.dart
import 'dart:convert' show utf8;
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:inlan_flutter/Config.dart';
import 'package:inlan_flutter/util/DataUtils.dart';
import 'package:inlan_flutter/util/I18nUtils.dart';
import 'package:inlan_flutter/util/JsonUtils.dart';
import 'package:inlan_flutter/util/LogUtils.dart';
import 'package:inlan_flutter/util/ToastUtils.dart';
import 'package:inlan_flutter/util/UpgradeUtils.dart';
import 'package:inlan_flutter/util/UuidUtils.dart';
class HttpsUtils {
static void apiPostWithUrl(
String url,
Map<String, dynamic> body,
BuildContext context,
StackTrace callPositionStackTrace,
State state,
callback(json)) async {
body["version"] = Config.apiVersion;
body["httpId"] = UuidUtils.v4();
body["lang"] = I18nUtils.languageCode();
body["path"] = url;
String fullUrl = Config.apiUrl + url;
final apiClient = http.Client();
try {
await apiClient
.post(fullUrl,
headers: {"Content-Type": "application/json"},
body: JsonUtils.encode(body))
.then((response) {
LogUtils.log(response.statusCode, StackTrace.current,
tag: "statusCode");
LogUtils.devLog(Config.apiUrl + url, callPositionStackTrace,
tag: "apiUrl " + url);
LogUtils.devLog(JsonUtils.prettyJson(body), callPositionStackTrace,
tag: "req");
LogUtils.devLog(
JsonUtils.prettyStr(response.body), callPositionStackTrace,
tag: "resp ${response.statusCode}");
switch (response.statusCode) {
case 200:
callback(JsonUtils.parse(response.body));
break;
case 400:
Map<String, dynamic> jsonObj = JsonUtils.parse(response.body);
state.setState(() {
ToastUtils.short(jsonObj["message"]);
});
break;
case 401:
Map<String, dynamic> jsonObj = JsonUtils.parse(response.body);
state.setState(() {
ToastUtils.withCallback(jsonObj["message"], () {
DataUtils.setByService('login_data', '-1');
DataUtils.setByService('isLogined', '-1');
Navigator.pushNamedAndRemoveUntil(
context, '/account', (Route<dynamic> route) => false);
});
});
break;
case 403:
break;
case 406:
UpgradeUtils().doForceUpgrade(context);
break;
case 422:
Map<String, dynamic> jsonObj = JsonUtils.parse(response.body);
state.setState(() {
ToastUtils.short(jsonObj["message"]);
});
break;
}
});
} finally {
apiClient.close();
}
}
}
My temporary solution
void initState() {
super.initState();
Timer timer = new Timer(new Duration(milliseconds: 1200), () {
// send Http here
});
}
Expected solution
- What causes the freeze?
- A better solution?
Metadata
Metadata
Assignees
Labels
Type
Projects
Relationships
Development
No branches or pull requests
Activity
tp commentedon Mar 5, 2020
@besthyhy
We ran into the same issue. For us our the issue was caused by our "User-Agent overwrite" not working anymore with Flutter 1.12, which cause the server to respond with status 400.
Maybe providing some user-agent header (
headers: {"User-Agent": "foo"}
), would also fix your issue and obliviate the need for the timeout?ghostgzt commentedon Mar 8, 2020
me too!
It is due to some https url!
beiger commentedon Apr 9, 2020
url: https://gank.io/api/v2/categories/Article
method: GET
my location: China
ios ui freeze on http request
lanistor commentedon Apr 9, 2020
Same issue. It's really a very very very terrible problem.
My environment:
http
: v0.12.0+2 ~ 4Dart
: 2.8.0Flutter
: 1.15.3Relative issues: dart-lang/http#400.
natebosch commentedon Apr 10, 2020
Does this replicate when you use
dart:io
directly to make the request?The comments so far don't give much to investigate - is this because there is a
Future
that does not resolve?Does anyone have a minimal reproduction?
lanistor commentedon Apr 11, 2020
@natebosch In my case, i was using
dart:io
andpackage:http/http.dart
at the same time in my one dart file,dart:io
is used to add platform info to http headers.After readed your words, i removed
import dart:io
line, it worked fine suddenly, and then i addedimport dart:io
back, it works fine too, and the error cannot occour ever, even i runflutter clean
to clean my build folder and run again. It' really wired.Now i removed
import dart:io
just in case. But i really don't know why.beiger commentedon Apr 11, 2020
If the website uses lets encrypt certification, the ui will be freeze on https request.
iOS platform
url: https://letsencrypt.org/
method: GET
use dart:io directly
natebosch commentedon Apr 13, 2020
@vifird - the concern isn't having imports to
dart:io
in the same file - it is whether the suspected bug is caused by this package, or bydart:io
. When you usepackage:http
on mobile with flutter it is acting as a thin wrapper aroundHttpClient
. When you use this package on the web it is a thin wrapper aroundHttpRequest
. Usually when something fundamentally doesn't work it can be reproduced without using this package at all, but by usingdart:io
ordart:html
directly. We ask for reproduction cases using these imports to help us route the bug to the right place. We can't solve any problem in this repository if the bug isn't caused by this repository.@beiger - Can you get more specific? Is there a Future that should complete but doesn't? Does the entire runtime crash?
If you can reproduce without using this package we will need to route the issue to the Dart SDK repo. Do you have a complete and minimal reproduction case?
beiger commentedon Apr 15, 2020
@natebosch
This is my code:
Letsencrypt CA url:

When you open this page, sometimes the page gets stuck in the middle, sometimes the animation gets stuck.
Other CA url:
The animation on the page is very smooth.
beiger commentedon Apr 15, 2020
Here is my iOS info:

There is no runtime crash.
natebosch commentedon Apr 15, 2020
Have you tried using an
HttpClient
fromdart:io
and setting thebadCertificateCallback
?https://api.dart.dev/stable/2.7.2/dart-io/HttpClient/badCertificateCallback.html
natebosch commentedon Apr 15, 2020
I think I'll move to the SDK repo for now. It's not entirely clear to me what the issue is, but I don't see any evidence it's related to
package:http
.beiger commentedon Apr 16, 2020
I'm using HttpClient from dart:io. I tried to set the badCertificateCallback, the program did not enter callback.
I've only had this kind of stuck situation since last month, and there are some people who have met earlier than me. It used to run well with the same code several month ago. This is only on IOS, Android is good.
mraleph commentedon Apr 23, 2020
I don't think there is enough information here for us to diagnose problem.
HTTP processing is done asynchronously so it can't just block your UI thread.
I would start by looking for exceptions in the logs.
72 remaining items