How can I change enableDrag or isDismissible on a showModalBottonSheet after is already constructed

0 votes

So I have an showModalBottonSheet, and I want that by default it can close with enableDrag or isDismissible as well, but, when the app is waiting Firebase to respond, after the user search for an object, I want to set enableDrag and isDismissible to false

I already tried setState and even GetX controller as well, I can't set this two to false and change the state after the showModalBottomSheet is constructed, it only works if the modal closes and open again

Apr 18, 2023 in Flutter by Ashwini
• 5,430 points
470 views

1 answer to this question.

0 votes

Unfortunately, you cannot change the enableDrag or isDismissible property of a showModalBottomSheet once it is already constructed. This is because these properties are set when the widget is built and cannot be changed dynamically.

One solution would be to create a new instance of the showModalBottomSheet widget with the desired properties when the Firebase response is received. You can do this by wrapping the showModalBottomSheet in a function and calling that function with the appropriate parameters when needed.

Here's an example:

void _showModal(BuildContext context, {bool enableDrag = true, bool isDismissible = true}) {
  showModalBottomSheet(
    context: context,
    enableDrag: enableDrag,
    isDismissible: isDismissible,
    builder: (BuildContext context) {
      return Container(
        child: Text('Modal content'),
      );
    },
  );
}

Then, you can call this function with the default values when you want to show the modal:

_showModal(context);

And call it again with the updated values when the Firebase response is received:

_showModal(context, enableDrag: false, isDismissible: false);

This will create a new instance of the showModalBottomSheet widget with the updated properties and display it on top of the previous one.

answered Apr 18, 2023 by vinayak

Related Questions In Flutter

0 votes
1 answer

How can I change the app display name build with Flutter?

Yes, you can change the app display ...READ MORE

answered Mar 21, 2023 in Flutter by venky
1,945 views
0 votes
1 answer

How can I create this kind of widget.Is There any packages available?

Based on the image you provided, it ...READ MORE

answered Apr 13, 2023 in Flutter by Anitha
200 views
0 votes
1 answer
0 votes
1 answer

How do you change the value inside of a textfield flutter?

To change the value inside a TextField ...READ MORE

answered Mar 26, 2023 in Flutter by Tej
6,616 views
0 votes
1 answer

setState() or markNeedsBuild called during build

The first error occurs because the ListView.builder ...READ MORE

answered Mar 10, 2023 in Android by vinayak
3,725 views
0 votes
1 answer

Cannot refresh AWS Web console during EC2 reboot

This never happens but you can see ...READ MORE

answered Oct 17, 2018 in AWS by Priyaj
• 58,090 points
543 views
0 votes
1 answer

What is the future of flutter?

Hi@MD, Flutter is a rather new cross-platform framework ...READ MORE

answered Jul 17, 2020 in Others by akhtar
• 38,230 points
926 views
0 votes
1 answer

What is Flutter?

Hi@akhtar, Flutter is an app SDK for building ...READ MORE

answered Jul 17, 2020 in Others by MD
• 95,440 points
1,082 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP