Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.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

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
带有提供程序包的Flatter Firebase未读邮件_Firebase_Flutter - Fatal编程技术网

带有提供程序包的Flatter Firebase未读邮件

带有提供程序包的Flatter Firebase未读邮件,firebase,flutter,Firebase,Flutter,我正在开发一个问答应用程序,在这个应用程序中,回答的每个问题都会导致被提问者和被回答者之间的聊天。如果有任何未读消息,我就无法向用户显示。问题包含字段read如果任何问题的读取为false,我希望在底部导航栏上显示通知徽章以下是我目前的流程: StreamBuilder获取已回答问题的列表: stream: _databaseService.questionCollection .orderBy('lastModified', descen

我正在开发一个问答应用程序,在这个应用程序中,回答的每个问题都会导致被提问者和被回答者之间的聊天。如果有任何未读消息,我就无法向用户显示。问题包含字段
read
如果任何问题的读取为false,我希望在底部导航栏上显示通知徽章以下是我目前的流程:

  • StreamBuilder获取已回答问题的列表:

                stream: _databaseService.questionCollection
                    .orderBy('lastModified', descending: true)
                    .snapshots(),
                builder: (context, snapshot) {
                  List<Widget> questionTiles = [];
                  if (!snapshot.hasData) {
                    return SpinKitPulse(
                      color: Colors.blue,
                    );
                  }
                  final questions = snapshot.data.docs;
                  for (var quest in questions) {
                    if (quest['user'] == loggedInUser.email &&
                        quest['isAnswered'] == true) {
                      \*fetch values*\
    
                      final questionTile = QuestionAnsweredTile(
                          \*populate values here*\
                          },
    
                      questionTiles.add(questionTile);
    
                      \* ERROR HERE - I use PROVIDER PACKAGE to update whether any question is unread *\
    
                      if (int.parse(lastModified) > int.parse(lastStudentClicked)) {
                        Provider.of<Notifications>(context, listen: false).incrementAnswered();
                      }
                      if (int.parse(lastModified) < int.parse(lastStudentClicked)) {
                        Provider.of<Notifications>(context, listen: false).decrementAnswered();
                      }
                    }
                  }```
    
    
  • 我得到以下错误:
  • 无法将此_InheritedProviderScope小部件标记为需要构建,因为框架已在构建小部件的过程中。只有当一个小部件的祖先当前正在构建时,才可以将其标记为需要在构建阶段构建。此异常是允许的,因为框架在子部件之前构建父部件,这意味着将始终构建脏子部件。否则,框架可能不会在构建阶段访问此小部件。
    调用setState()或markNeedsBuild()的小部件是:_InheritedProviderScope
    值:“通知”的实例
    倾听价值观
    当发出违规调用时,当前正在生成的小部件是:StreamBuilder
    肮脏的
    状态:_StreamBuilderBaseState#e6b9d
    
    class Notifications extends ChangeNotifier {
      int answered = 0;
      int unanswered = 0;
    
      void incrementAnswered() {
        answered += 1;
        notifyListeners();
      }
    
      void decrementAnswered() {
        answered -= 1;
        notifyListeners();
      }
    
      void incrementUnanswered() {
        unanswered += 1;
        notifyListeners();
      }
    
      void decrementUnanswered() {
        unanswered -= 1;
        notifyListeners();
      }
    }
    
    This _InheritedProviderScope<Notifications> 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.
    The widget on which setState() or markNeedsBuild() was called was: _InheritedProviderScope<Notifications>
      value: Instance of 'Notifications'
      listening to value
    The widget which was currently being built when the offending call was made was: StreamBuilder<QuerySnapshot>
      dirty
      state: _StreamBuilderBaseState<QuerySnapshot, AsyncSnapshot<QuerySnapshot>>#e6b9d