我的代码:
小部件构建(BuildContext 上下文){
var s=CubicCounter.get(context);
返回
区块提供者(
创建:(BuildContext 上下文)=> CubicCounter(),
孩子:BlocConsumer
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)