点击button按钮跳转时,出现的问题,
Unhandled Exception: NoSuchMethodError: The method 'ancestorStateOfType' was called on null.
通常是由于传入的buildContext为空导致的。
把BuildContext参数传过去就可以了,如下所示。
Widget _persionButtonView(BuildContext context){
return new Container(
padding: const EdgeInsets.only(left: 30,right: 30,top: 0),
child: new MaterialButton(
onPressed:(){
Navigator.of(context).pushNamed('/route/persion'); //跳转方法
},
child: Text("个人中心",
style: TextStyle(color: Colors.white),
),
color: Colors.red,
),
);
}
网友评论