android - Release APK behaves differently than debug with type Future is not a subtype of FutureOr error
问题描述
Im implementing a simple app with a login screen using bloc pattern. The app runs fine when running on debug mode on the android emulator or on my android phone from android studio. When I tried the release-apk with no changes on the code, I encounter the Future is not a subtype of FutureOr error.
Here's the method on the bloc with the logic:
void submit() async{
_loginStateController.sink.add(LoginStateLoading());
User user = User();
user.email = emailController.text;
user.password = passwordController.text;
String responseBody = await ApiClient.postUser(user, "/login").catchError( (error){
developer.log("error_while_posting_user: " + error.toString());
String errorMessage = error.toString();
if(errorMessage == "missing email" || errorMessage == "missing password"){
errorMessage = "Datos faltantes";
}
else if(errorMessage == "incorrect email or password"){
errorMessage = "Correo o contraseña incorrecta";
}
else{
errorMessage = "Error inesperado";
}
_loginStateController.sink.add( LoginStateError(errorMessage));
return;
});
Map<String, dynamic> responseMap = json.decode(responseBody);
Utils.saveLoginInfo(responseMap);
_loginStateController.sink.add(LoginStateReady());
}
Here's the code where the http request is being made:
static Future<String> postUser(User user, String path) async {
Map<String, String> headers = Map();
headers["content-type"] = "application/json";
Map<String, dynamic> bodyMap = user.toJson();
String body = jsonEncode(bodyMap);
try {
final response = await http.post(
API_ENDPOINT + path, headers: headers, body: body).catchError( (error) {
return Future.error(error);
}).timeout(Duration(milliseconds: 10000));
if (response == null) {
return Future.error("request error");
}
if (response.statusCode != 200) {
String errorMessage = jsonDecode(response.body)["message"];
return Future.error(errorMessage);
}
return response.body;
}
catch (Exception) {
return Future.error(Exception.toString());
}
return "";
}
I've tried flutter clean several times and still getting the error.
解决方案
have you checked if you have internet permission in the AndroidManifest.xml?
Can you try adding this line in the AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
推荐阅读
- android-studio - 在 Android Studio 中如何删除指南?
- algorithm - 解决特定情况下替换路径问题的算法
- ssl - OpenShift 3.11 是否会阻止安全路由上的任何 SSLv3 流量?
- javascript - 使用 .put 从 API 生成的数组中编辑项目
- javascript - 如何将 arrayUnion 与 AngularFirestore 一起使用?
- python - 如何优化计算分布相似度的函数
- python - 为什么 Fore.BLUE 使文本以随机字符开头而不是使文本变为蓝色?
- c++ - 不能包括
在我的 mfc 应用程序中,编译器错误 - java - 使用 Maven 和 Eclipse 测试 Java 模块的白盒单元测试依赖项
- c++ - 如何在数组中交换中心?