你好,我在运行后收到此错误,但在颤振中对此有任何解决方案

时间:2021-07-21 14:52:52

标签: flutter

我的代码: 小部件构建(BuildContext 上下文){ var s=CubicCounter.get(context); 返回 区块提供者( 创建:(BuildContext 上下文)=> CubicCounter(), 孩子:BlocConsumer( builder: (BuildContext context, state) => Scaffold( 键:s.bottomSheet, 应用栏:应用栏(), 身体: 创建(),

          floatingActionButton:
          FloatingActionButton(onPressed: () {
            if (s.open) {
             s.setOpen(false);
              s.bottomSheet.currentState!.showBottomSheet((context) =>
                  Container(
                    width: double.infinity,
                    color: Colors.grey[200],

                    child: Padding(
                      padding: const EdgeInsets.all(20.0),
                      child: Form(
                        key: s.formKey,
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          children: [
                            textF(preIcon: Icons.title,
                                Hinttext: "Title",
                                COntrol: title,
                                tap: ""),
                            SizedBox(height: 10,)
                            , textF(preIcon: Icons.date_range,
                                Hinttext: "Date",
                                COntrol: date,
                                tap: ontap),
                            SizedBox(height: 10,),
                            textF(preIcon: Icons.timelapse_rounded,
                                Hinttext: "Time",
                                COntrol: time,
                                tap: time_pick)


                          ],


                        ),
                      ),
                    ),
                  ));
            }
            else {
             s.setOpen(true);
            //  Navigator.pop(context);
              if (title.text != null && date.text != null &&
                  time.text != null) {
                s.insertToDatabase(time: time.text, title: title.text, date: date.text);
                title.text ="";
                date.text ="";
                time.text="";

              }

            }
          }
            , child: Icon(s.open ? Icons.edit : Icons.add),),

          bottomNavigationBar:

          BottomNavigationBar(
            onTap: (int index) {
             s.setIndex(index);
            },
            currentIndex: s.index,
            items: [
              BottomNavigationBarItem(
                icon: Icon(Icons.add_circle_outline), label: "Create",

              ),
              BottomNavigationBarItem(
                  icon: Icon(Icons.done), label: "done"),
              BottomNavigationBarItem(
                  icon: Icon(Icons.archive_outlined), label: "Archive")


            ],)


      ),
      listener: (BuildContext context, Object? state) {  },

    ),
  );

}

错误:

在构建 Nav(dirty) 时抛出了以下断言: BlocProvider.of() 使用不包含 CubicCounter 的上下文调用。

    No ancestor could be found starting from the context that was passed to BlocProvider.of<CubicCounter>().

    This can happen if the context you used comes from a widget above the BlocProvider.

    The context used was: Nav(dirty)
    

0 个答案:

没有答案