当前位置:网站首页>flutter 报错记录:navigator.dart‘: Failed assertion: line 4041 pos 12: ‘!_debugLocked‘: is not true.
flutter 报错记录:navigator.dart‘: Failed assertion: line 4041 pos 12: ‘!_debugLocked‘: is not true.
2022-07-21 05:06:00 【走向大前端】
做项目时登录页遇到的一个小问题,我在请求完成后要跳转到页面,代码如下
LoginApi.phoneLogin(phone: phoneNum, code: identifyingCode, checkid: codeId).then((userToken){ print(userToken); Navigator.pop(context); SPUtils.saveUserToken(userToken); Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => (BaseTabBar()))); }).catchError((e){ print(e); });
遇到报错信息: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 4041 pos 12: '!_debugLocked': is not true.
因为是登录页面跳转所以使用的是Navigator.pushReplacement,查到原因是不能在build的过程中跳转,需要给跳转加一个延时。
解决代码如下:
LoginApi.phoneLogin(phone: phoneNum, code: identifyingCode, checkid: codeId).then((userToken){ print(userToken); Navigator.pop(context); SPUtils.saveUserToken(userToken); Future.delayed(Duration.zero, () { Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => (BaseTabBar()))); }); }).catchError((e){ print(e); });
边栏推荐
猜你喜欢
随机推荐
$.each的用法
Namespace namespace
Data analysis on the fourth match
xml建模
visual studio第三方库添加——Eigen
useMemo和useCallback的区别以及使用场景
Available parameters are [list] error in batch upload
JS数据类型在内存上的储存原理
碎碎念 碎碎念 起稿
Deep analysis of string -- StrCmp & strncmp
再见了,各位(虽然没人会注意到)
格式化时间
[C语言函数数组]带走我最后的思念吧 光!
General paging 01
User defined MVC addition, deletion, modification and query
In depth analysis of string -- strcpy & strncpy
Output statements on the console
xml解析
移动端 pc端 小程序 UI框架选择
10.【file的打开格式及其判断是否打开】