当显示底部工作表时,有没有办法在屏幕上保持活动的 GestureDetector ?

Fai*_*Dae 2 android ios dart flutter bottom-sheet

我正在使用GetX包来显示bottomSheet.

我希望用户能够在我的底部工作表打开时单击屏幕,如下图所示。

我怎样才能做到这一点?

kri*_*yaa 8

答案是


为什么?

根据Flutter 文档

模态底部表单是菜单或对话框的替代方案,可防止用户与应用程序的其余部分进行交互。

底部表单的主要目的是防止用户与应用程序的其余部分交互。


我们怎样才能克服这个问题呢?

使用持久的底部工作表,即使用showBottomSheet.

密切相关的小部件是一个持久的底部表单,它显示补充应用程序主要内容的信息,而不会阻止用户与应用程序交互。

输出:

在此输入图像描述

在此输入图像描述

代码:

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: showSheet(),
      ),
    );
  }
}

class showSheet extends StatefulWidget {
  const showSheet({Key? key}) : super(key: key);

  @override
  State<showSheet> createState() => _showSheetState();
}

class _showSheetState extends State<showSheet> {
  void displayPersistentBottomSheet() {
    Scaffold.of(context).showBottomSheet<void>((BuildContext context) {
      return Container(
        color: Colors.amber,
        height: 200,   //  Change this according to your need
        child: const Center(child: Text("Image Filter Here")),
      );
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: FilledButton(
        onPressed: displayPersistentBottomSheet,
        child: const Text(
          'Draggable Widget Here',
          style: TextStyle(color: Colors.white),
        ),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

可以使用 Getx 来完成吗?

不幸的是,没有,因为getx仅支持模态底部表bottomShet的替代方案,并且没有任何持久底部表的替代方案。

  • 好的。我有同样的答案:“你不能”。但我没有发布它,因为我认为_也许_有一个解决方法...... (2认同)