Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振-在生成期间调用setState()或markNeedsBuild()_Flutter_Google Cloud Firestore_Provider - Fatal编程技术网

Flutter 颤振-在生成期间调用setState()或markNeedsBuild()

Flutter 颤振-在生成期间调用setState()或markNeedsBuild(),flutter,google-cloud-firestore,provider,Flutter,Google Cloud Firestore,Provider,从Firebase云加载帖子时显示错误。。我正在应用程序中使用提供程序 setState() or markNeedsBuild() called during build. 详细错误 ════════ Exception caught by foundation library ════════════════════════════════ The following assertion was thrown while dispatching notifications for Pos

从Firebase云加载帖子时显示错误。。我正在应用程序中使用提供程序

setState() or markNeedsBuild() called during build.
详细错误


════════ Exception caught by foundation library ════════════════════════════════
The following assertion was thrown while dispatching notifications for PostFunctions:
setState() or markNeedsBuild() called during build.

This _InheritedProviderScope<PostFunctions> widget cannot be marked as needing to build because the framework is already in the process of building widgets.  A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.

════════ 基金会例外════════════════════════════════
为PostFunction发送通知时引发了以下断言:
在生成过程中调用setState()或markNeedsBuild()。
无法将此_InheritedProviderScope小部件标记为需要构建,因为框架已在构建小部件的过程中。只有当一个小部件的祖先当前正在构建时,才可以将其标记为需要在构建阶段构建。此异常是允许的,因为框架在子部件之前构建父部件,这意味着将始终构建脏子部件。否则,框架可能不会在构建阶段访问此小部件。
当我加载Post时我的代码

 Widget feedBody(BuildContext context) {
    return SingleChildScrollView(
      child: Padding(
        padding: const EdgeInsets.only(top: 8.0),
        child: Container(
          child: StreamBuilder<QuerySnapshot>(
            stream: FirebaseFirestore.instance
                .collection('posts')
                .orderBy('time', descending: true)
                .snapshots(),
            builder: (context, snapshot) {
              if (snapshot.connectionState == ConnectionState.waiting) {
                return Center(
                  child: SizedBox(
                    height: 200.0,
                    width: 200.0,
                    child: Lottie.asset('assets/animations/loading.json'),
                  ),
                );
              } else {
                return loadPosts(context, snapshot);
              }
            },
          ),
          height: MediaQuery.of(context).size.height * 0.80,
          width: MediaQuery.of(context).size.width,
          decoration: BoxDecoration(
            color: constantColors.darkColor.withOpacity(0.6),
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(18.0),
              topRight: Radius.circular(18.0),
            ),
          ),
        ),
      ),
    );
  }
Widget提要(BuildContext){
返回SingleChildScrollView(
孩子:填充(
填充:仅限常量边集(顶部:8.0),
子:容器(
孩子:StreamBuilder(
流:FirebaseFirestore.instance
.collection(“posts”)
.orderBy('time',降序:true)
.snapshots(),
生成器:(上下文,快照){
if(snapshot.connectionState==connectionState.waiting){
返回中心(
孩子:大小盒子(
高度:200.0,
宽度:200.0,
子项:Lottie.asset('assets/animations/load.json'),
),
);
}否则{
返回loadpost(上下文、快照);
}
},
),
高度:MediaQuery.of(上下文).size.height*0.80,
宽度:MediaQuery.of(context).size.width,
装饰:盒子装饰(
颜色:恒常色。深色。不透明度(0.6),
borderRadius:仅限borderRadius(
左上:半径。圆形(18.0),
右上角:半径。圆形(18.0),
),
),
),
),
);
}
我的装载邮政编码

Widget loadPosts(
      BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
    return ListView(
        children: snapshot.data.docs.map((DocumentSnapshot documentSnapshot) {
      Provider.of<PostFunctions>(context, listen: false)
          .showTimeAgo(documentSnapshot.data()['time']);

      return Container(
        height: MediaQuery.of(context).size.height * 0.62,
        width: MediaQuery.of(context).size.width,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: const EdgeInsets.only(
                top: 8.0,
                left: 8.0,
              ),
              child: Row(
                children: [
                  GestureDetector(
                    onTap: () {
                      if (documentSnapshot.data()['useruid'] !=
                          Provider.of<Authenticationss>(context, listen: false)
                              .getUserUid) {
                        Navigator.pushReplacement(
                          context,
                          PageTransition(
                            child: AltProfile(
                              userUid: documentSnapshot.data()['useruid'],
                            ),
                            type: PageTransitionType.bottomToTop,
                          ),
                        );
                      }
                    },
                    child: CircleAvatar(
                      backgroundColor: constantColors.blueGreyColor,
                      radius: 20.0,
                      backgroundImage:
                          NetworkImage(documentSnapshot.data()['userimage']),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(left: 8.0),
                    child: Container(
                      width: MediaQuery.of(context).size.width * 0.6,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Container(
                            child: Text(
                              documentSnapshot.data()['caption'],
                              style: TextStyle(
                                  color: constantColors.greenColor,
                                  fontWeight: FontWeight.bold,
                                  fontSize: 16.0),
                            ),
                          ),
                          Container(
                            child: RichText(
                              text: TextSpan(
                                text: documentSnapshot.data()['username'],
                                style: TextStyle(
                                  color: constantColors.blueColor,
                                  fontSize: 14.0,
                                  fontWeight: FontWeight.bold,
                                ),
                                children: <TextSpan>[
                                  TextSpan(
                                    text:
                                        ' , ${Provider.of<PostFunctions>(context, listen: false).getImageTimePosted.toString()}',
                                    style: TextStyle(
                                      color: constantColors.lightColor
                                          .withOpacity(0.8),
                                    ),
                                  )
                                ],
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                  Container(
                    width: MediaQuery.of(context).size.width * .2,
                    height: MediaQuery.of(context).size.height * 0.05,
                    child: StreamBuilder<QuerySnapshot>(
                      stream: FirebaseFirestore.instance
                          .collection('posts')
                          .doc(documentSnapshot.data()['caption'])
                          .collection('awards')
                          .snapshots(),
                      builder: (context, snapshot) {
                        if (snapshot.connectionState ==
                            ConnectionState.waiting) {
                          return Center(
                            child: CircularProgressIndicator(),
                          );
                        } else {
                          return ListView(
                            scrollDirection: Axis.horizontal,
                            children: snapshot.data.docs
                                .map((DocumentSnapshot documentSnapshot) {
                              return Container(
                                height: 30.0,
                                width: 30.0,
                                child: Image.network(
                                    documentSnapshot.data()['award']),
                              );
                            }).toList(),
                          );
                        }
                      },
                    ),
                  ),
                ],
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 8.0),
              child: Container(
                height: MediaQuery.of(context).size.height * 0.45,
                width: MediaQuery.of(context).size.width,
                child: FittedBox(
                  child: Image.network(
                    documentSnapshot.data()['postimage'],
                    scale: 2,
                  ),
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 8.0),
              child: Padding(
                padding: const EdgeInsets.only(left: 21.0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Container(
                      width: 80.0,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          GestureDetector(
                            onLongPress: () {
                              Provider.of<PostFunctions>(context, listen: false)
                                  .showLikes(
                                context,
                                documentSnapshot.data()['caption'],
                              );
                            },
                            onTap: () {
                              print('adding like');
                              Provider.of<PostFunctions>(context, listen: false)
                                  .addLike(
                                      context,
                                      documentSnapshot.data()['caption'],
                                      Provider.of<Authenticationss>(context,
                                              listen: false)
                                          .userUid);
                            },
                            child: Icon(
                              FontAwesomeIcons.heart,
                              color: constantColors.redColor,
                              size: 22.0,
                            ),
                          ),
                          StreamBuilder<QuerySnapshot>(
                            stream: FirebaseFirestore.instance
                                .collection('posts')
                                .doc(documentSnapshot.data()['caption'])
                                .collection('likes')
                                .snapshots(),
                            builder: (context, snapshot) {
                              if (snapshot.connectionState ==
                                  ConnectionState.waiting) {
                                return Center(
                                  child: CircularProgressIndicator(),
                                );
                              } else {
                                return Padding(
                                  padding: const EdgeInsets.only(left: 8.0),
                                  child: Text(
                                    snapshot.data.docs.length.toString(),
                                    style: TextStyle(
                                      color: constantColors.whiteColor,
                                      fontWeight: FontWeight.bold,
                                      fontSize: 18.0,
                                    ),
                                  ),
                                );
                              }
                            },
                          )
                        ],
                      ),
                    ),
                    Container(
                      width: 80.0,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          GestureDetector(
                            onTap: () {
                              Provider.of<PostFunctions>(context, listen: false)
                                  .shotCommentSheets(context, documentSnapshot,
                                      documentSnapshot.data()['caption']);
                            },
                            child: Icon(
                              FontAwesomeIcons.comment,
                              color: constantColors.blueColor,
                              size: 22.0,
                            ),
                          ),
                          StreamBuilder<QuerySnapshot>(
                            stream: FirebaseFirestore.instance
                                .collection('posts')
                                .doc(documentSnapshot.data()['caption'])
                                .collection('comments')
                                .snapshots(),
                            builder: (context, snapshot) {
                              if (snapshot.connectionState ==
                                  ConnectionState.waiting) {
                                return Center(
                                  child: CircularProgressIndicator(),
                                );
                              } else {
                                return Padding(
                                  padding: const EdgeInsets.only(left: 8.0),
                                  child: Text(
                                    snapshot.data.docs.length.toString(),
                                    style: TextStyle(
                                      color: constantColors.whiteColor,
                                      fontWeight: FontWeight.bold,
                                      fontSize: 18.0,
                                    ),
                                  ),
                                );
                              }
                            },
                          )
                        ],
                      ),
                    ),
                    Container(
                      width: 80.0,
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          GestureDetector(
                            onLongPress: () {
                              Provider.of<PostFunctions>(context, listen: false)
                                  .showAwardPresenter(context,
                                      documentSnapshot.data()['caption']);
                            },
                            onTap: () {
                              Provider.of<PostFunctions>(context, listen: false)
                                  .showReward(context,
                                      documentSnapshot.data()['caption']);
                            },
                            child: Icon(
                              FontAwesomeIcons.award,
                              color: constantColors.yellowColor,
                              size: 22.0,
                            ),
                          ),
                          StreamBuilder<QuerySnapshot>(
                            stream: FirebaseFirestore.instance
                                .collection('posts')
                                .doc(documentSnapshot.data()['caption'])
                                .collection('awards')
                                .snapshots(),
                            builder: (context, snapshot) {
                              if (snapshot.connectionState ==
                                  ConnectionState.waiting) {
                                return Center(
                                  child: CircularProgressIndicator(),
                                );
                              } else {
                                return Padding(
                                  padding: const EdgeInsets.only(left: 8.0),
                                  child: Text(
                                    snapshot.data.docs.length.toString(),
                                    style: TextStyle(
                                      color: constantColors.whiteColor,
                                      fontWeight: FontWeight.bold,
                                      fontSize: 18.0,
                                    ),
                                  ),
                                );
                              }
                            },
                          )
                        ],
                      ),
                    ),
                    Spacer(),
                    Provider.of<Authenticationss>(context, listen: false)
                                .getUserUid ==
                            documentSnapshot.data()['useruid']
                        ? IconButton(
                            icon: Icon(
                              EvaIcons.moreVertical,
                              color: constantColors.whiteColor,
                            ),
                            onPressed: () {
                              Provider.of<PostFunctions>(context, listen: false)
                                  .showPostOptions(context,
                                      documentSnapshot.data()['caption']);
                            },
                          )
                        : Container(
                            height: 0.0,
                            width: 0.0,
                          ),
                  ],
                ),
              ),
            ),
          ],
        ),
      );
    }).toList());
  }
}

Widget加载帖子(
BuildContext上下文,异步快照(快照){
返回列表视图(
子项:snapshot.data.docs.map((DocumentSnapshot DocumentSnapshot){
Provider.of(上下文,侦听:false)
.showTimeAgo(documentSnapshot.data()['time']);
返回容器(
高度:MediaQuery.of(上下文).size.height*0.62,
宽度:MediaQuery.of(context).size.width,
子:列(
mainAxisAlignment:mainAxisAlignment.start,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
填充物(
填充:仅限常量边设置(
排名:8.0,
左:8.0,
),
孩子:排(
儿童:[
手势检测器(
onTap:(){
如果(documentSnapshot.data()['useruid'])=
Provider.of(上下文,侦听:false)
.getUserUid){
导航器。更换(
上下文
页面转换(
子:AltProfile(
userUid:documentSnapshot.data()['userUid'],
),
类型:PageTransitionType.bottomToTop,
),
);
}
},
孩子:圆环星(
背景颜色:constantColors.blueGreyColor,
半径:20.0,
背景图片:
NetworkImage(documentSnapshot.data()['userimage']),
),
),
填充物(
填充:仅限常量边集(左:8.0),
子:容器(
宽度:MediaQuery.of(context).size.width*0.6,
子:列(
mainAxisAlignment:mainAxisAlignment.start,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
容器(
子:文本(
documentSnapshot.data()['caption'],
样式:TextStyle(
颜色:君士坦丁堡,绿色,
fontWeight:fontWeight.bold,
字体大小:16.0),
),
),
容器(
孩子:RichText(
text:TextSpan(
text:documentSnapshot.data()['username'],
样式:TextStyle(
颜色:君士坦色,蓝色,
字体大小:14.0,
fontWeight:fontWeight.bold,
),
儿童:[
TextSpan(
正文:
“,${Provider.of(context,listen:false).getImageTimePosted.toString()}”,
样式:TextStyle(
颜色:君士坦丁堡
.不透明度(0.8),
),
)
],
),
),
if(mounted){
   setState((){

   });
}