首页 > 解决方案 > 禁用在底部工作表模式上的拖动

问题描述

我想使用一个模态的 bottomSheetModal,我想在其中显示一个带有一些元素的 gridView。我使用showModalBottomSheet方法将模态带入视图。

showModalBottomSheet(
    context: context,
    isScrollControlled: true,
    builder: (BuildContext context) {
        return Container(
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height / 2,
            color: Colors.grey[300],
            child: CategoryModal(),
        );
    },
);

在 CategoryModal 我有一个从数据库中获取一些数据的未来:

CategoryModal extends StatelessWidget {
Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
         ...
          Expanded(
            child: FutureBuilder<List<Category>>(
                future: CategoryRepository.getAll(),
                builder: (BuildContext context, AsyncSnapshot<List<Category>> snapshot) {
                  if (snapshot.connectionState == ConnectionState.done) {
                    if (snapshot.hasError) {
                      return Text(
                        snapshot.error.toString(),
                      );
                    }

                    return getCategoriesGrid(snapshot.data);
                  }

                  return Text("Loading");
                }),
          ),
        ],
      ),
    );
  }
}

我遇到的问题是,modal有可拖动的选项来关闭,如果我慢慢往下拉,每次都会刷新数据。我发现 BottomSheet 类有一个参数,enableDrag它禁用拖动,但不适用于该showModalBottomSheet方法。

有没有办法停止刷新数据或禁用模式的拖动选项?

标签: androidiosflutterflutter-layout

解决方案


这是您的问题的解决方案,

   showModalBottomSheet(
    context: context,
    enableDrag: false,
    isScrollControlled: true,

推荐阅读