Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to keep active GestureDetector on the screen when the bottom sheet is showing?

I'm using the GetX package to display a bottomSheet.

I want users to be able to click on the screen when my bottom sheet is opened, like the following image.

How can I do this?

like image 469
Faiz Ahmad Dae Avatar asked Nov 24 '25 17:11

Faiz Ahmad Dae


2 Answers

The answer is no


Why?

According to the Flutter documentation:

A modal bottom sheet is an alternative to a menu or a dialog and prevents the user from interacting with the rest of the app.

The main purpose of the bottom sheet is to prevent the user from interacting with the rest of the app.


How can we overcome this?

Use a persistent bottom sheet, i.e., using showBottomSheet.

A closely related widget is a persistent bottom sheet, which shows information that supplements the primary content of the app without preventing the user from interacting with the app.

Output:

Enter image description here

Enter image description here

Code:

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),
        ),
      ),
    );
  }
}

Can it be done using Getx?

Unfortunately no, because getx supports only bottomShet which is an alternative to Modal Bottom Sheet and there isn't any alternative to a persistent bottom sheet.

like image 137
krishnaacharyaa Avatar answered Nov 26 '25 09:11

krishnaacharyaa


Instead of using Get.bottomSheet, you can use a Stack widget and use it something like this:

Widget yourPhotoEditingWidget() {
  bool onShadowButtonTapped = false;
  return Stack(
    children: [
      Column(
        children: [
          yourDraggableWidget(),
          Align(
            alignment: Alignment.center,
            child: MaterialButton(
              color: Colors.orange,
              onPressed: () {
                onShadowButtonTapped = !onShadowButtonTapped;
                setState(() {});
              },
              child: const Text(
                'Shadow',
                style: TextStyle(color: Colors.white),
              ),
            ),
          ),
        ],
      ),
      if (onShadowButtonTapped)
        Align(
          alignment: Alignment.bottomCenter,
          child: Container(
            height: 150,
            width: 300,
            color: Colors.orange,
            child: const Center(
              child: Text(
                'Your Widget',
                style: TextStyle(color: Colors.white),
              ),
            ),
          ),
        ),
    ],
  );
}
like image 37
Shubhanshu Kashiva Avatar answered Nov 26 '25 10:11

Shubhanshu Kashiva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!