美文网首页
Flutter context在instate中报null问题

Flutter context在instate中报null问题

作者: 懵懵懂懂_YOYO | 来源:发表于2022-03-23 13:48 被阅读0次

    When the exception was thrown, this was the stack:

    #0      State.context.<anonymous closure> (package:flutter/src/widgets/framework.dart:909:9)

    如果在instate 中报context为null 问题,因为instate在生命周期中重要一环,在初始化创建页面的必经之路,所以要做一些本地数据网络数据的获取及初始化,可以给使用的context 方法价格延时操作,如下:

    Future.delayed(Duration.zero).then((value)async {

    //使用context方法

    });

    相关文章

      网友评论

          本文标题:Flutter context在instate中报null问题

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