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无效

0
1
CrazyCodeBoy
因为registration方法需要返回值
2021-05-17
共1条回复

Flutter高级进阶实战-仿哔哩哔哩-掌握Flutter高阶技能

一次性掌握Flutter高阶技能+商业级复杂项目架构设计与开发方案

1723 学习 · 870 问题

查看课程