错误解析:
在运行中,原因是因为控件、响应事件还没有构建完毕,延时加载即可解决问题
解决方法:
添加延时
void _addIndex() {
/*这里要延时加载 否则会抱The widget on which setState() or markNeedsBuild() was called was:错误*/
Future.delayed(Duration(milliseconds: 200)).then((e) {
setState(() {
if(_userName == ''){
Navigator.push(context, MaterialPageRoute(builder: (_) {
return new LoginPage();
})
);};
});
});
}