flutter - 提供程序在执行时未更新,Navigator.pop(context) 在颤动
问题描述
在这里,我使用提供程序包进行状态管理。
我在 floatingActionButton 中有一个 SpeedDial 小部件。每当我 mainGoalList
使用 speedDial 在列表中添加某些内容时,Navigator.pop(context);
它确实会返回到页面但不会更新列表。
快速拨号
SpeedDialChild(
child: Icon(Icons.book),
backgroundColor: Colors.blue,
label: 'Add Notes',
labelStyle: TextStyle(
fontSize: 18.0,
color: Colors.black,
),
onTap: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) => SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context)
.viewInsets
.bottom),
child: AddNotes(),
),
));
}),
加注
Center(
child: FlatButton(
onPressed: () {
if (_actcontroller.text == null) {
print("Cannot add null topic");
} else {
addingTheNotes();
Navigator.pop(context);
}
},
child: Text("Add"),
color: Colors.blue,
),
)
添加注释
addingTheNotes() {
theDataProvider.ourAllnotes.add(
TodaysNoteClass(
note: _actcontroller.text,
dateTime: theDataProvider.notesChoosenDate,
status: false,
),
);
theDataProvider.showingTheTodaysList();
}
这是更改通知
List<TodaysNoteClass> _ourAllnotes = [];
List<TodaysNoteClass> get ourAllnotes => _ourAllnotes;
set ourAllnotes(List<TodaysNoteClass> val) {
_ourAllnotes = val;
notifyListeners();
}
消费类,这是我展示笔记的地方
class HomePage extends StatefulWidget {
static const String id = 'homePage';
final String todaysDate =
DateFormat('d MMMM').format(DateTime.now()).toLowerCase();
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
var theDataProvider;
Widget build(BuildContext context) {
theDataProvider = Provider.of<TheData>(context, listen: false);
return Consumer<TheData>(
builder: (context, value, child) => SingleChildScrollView(
child: Container(
child: Column(
children: [
Container(
height: 120,
child: TodaysNote(),
),
],
),
),
),
);
}
}
这是 TodaysNote 课程
class TodaysNote extends StatefulWidget {
TodaysNote({Key key}) : super(key: key);
bool boxChecked = false;
@override
_TodaysNoteState createState() => _TodaysNoteState();
}
class _TodaysNoteState extends State<TodaysNote> {
var theDataProvider;
Widget build(BuildContext context) {
theDataProvider = Provider.of<TheData>(context, listen: false);
return Consumer<TheData>(
builder: (context, value, child) => Container(
child: theDataProvider.showingTheTodaysList(),
),
);
}
}
但是现在当我转到另一个屏幕然后来到上一个屏幕时。我看到了更新的列表。我已经用提供者包装了主文件,用消费者包装了文件,但没有用。
这背后的原因可能是什么?
解决方案
推荐阅读
- html - 根据集合的大小动态添加行
- python - 使用枚举选择和运行特定子方法的 Pythonic 方式?
- java - 1.11.2 当玩家尝试加入/ping 服务器时,Minecraft 服务器崩溃
- material-ui - 如何设置material-ui表格单元格的固定宽度以截断内容
- python - seaborn 两角对图
- java - 文件下载时的问题
- html - 内容没有填满 flexbox 的整个高度
- python - 硒可以减慢或停止Windows服务器吗?
- google-cloud-functions - GCP 大型 PubSub 消息混淆 Cloud Function 触发器
- swift - 快速将图像添加到另一个类中的调用函数