美文网首页
Unhandled Exception: NoSuchMetho

Unhandled Exception: NoSuchMetho

作者: 江河_ios | 来源:发表于2020-08-11 18:46 被阅读0次

    点击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,
    
    ),
    
    );
      }
    

    相关文章

      网友评论

          本文标题:Unhandled Exception: NoSuchMetho

          本文链接:https://www.haomeiwen.com/subject/dnswrktx.html