【发布时间】:2022-07-05 23:28:14
【问题描述】:
我向 DraggableScrollableSheet 添加了一个监听器。当我对函数 DraggableScrollableNotification DSNotification 上的 DSNotification.extent 进行打印时,它可以工作并且它向我显示最大值为 0.49 但是当我添加 if 测试和 setState 时,我没有得到正确的价值。它不会与 setState 一起使用,当我删除它时它总是给我错误的!
NotificationListener<DraggableScrollableNotification>(
onNotification:
(DraggableScrollableNotification DSNotification) {
if (DSNotification.extent == 0.49) {
// setState(() {
//print(DSNotification.extent);
scrolable = true;
// });
}
if (DSNotification.extent <= 0.49) {
//setState(() {
scrolable = false;
//print(DSNotification.extent);
//});
}
print(scrolable);
return true;
},
child: DraggableScrollableSheet(
controller: controller,
initialChildSize: 0,
minChildSize: 0.0,
maxChildSize: 0.49,
builder: (_, scrollController) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.transparent),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(15),
topRight: Radius.circular(15))),
child: ListView(controller: scrollController, children: [
nfController.myWidget,
]),
);
},
),
),
【问题讨论】:
-
你在模态底页中使用这个吗?
-
不,它在堆栈小部件中
-
你可以包含完整的小部件minimal-reproducible-example
标签: flutter