await不生效 后面也会马上执行
来源:4-7 注册模块设计与实现

未來太漫長
2021-05-14
var result =
await LoginDao.registration(userName, password, imoocid, orderId);
print(2222);
print(result);
if (result[‘code’] == 0) {
print(‘注册成功’);
if (widget.onJumpToLogin != null) {
widget.onJumpToLogin();
}
} else {
print(result[‘meg’]);
}
按照视频中写完之后 发现会报错
flutter: 2222
flutter: null
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: NoSuchMethodError: The method ‘[]’ was called on null.
Receiver: null
Tried calling:
flutter: HiNet:{code: 5004, msg: 请先购买课程@https://coding.imooc.com/class/487.html}
await没有等待 直接执行到后面 导致result是null 请问这是为什么
1回答
-
未來太漫長
提问者
2021-05-14
问题找到了 是login_dao.dart中
static registration(
String userName, String password, String imoocId, String orderId) {
return _send(userName, password, imoocId: imoocId, orderId: orderId);
}
一开始没加return 直接调用了_send 请问不加return 直接调用_send为什么会导致外部的await无效
012021-05-17
相似问题