Skip to content
Mahgoub

A Software Developer who does not let his schooling interfere with his education

Mahgoub

A Software Developer who does not let his schooling interfere with his education

Use Flutters StatefulBuilder to update state of a ModalBottomSheet

mmahgoub, November 1, 2019November 4, 2023

You can use Flutter’s StatefulBuilder to wrap your ModalBottomSheet as follows:

showModalBottomSheet(
    context: context,
    builder: (context) {
      return StatefulBuilder(
          builder: (BuildContext context, StateSetter setState /*You can rename this!*/) {
        return Container(
          height: heightOfModalBottomSheet,
          child: RaisedButton(onPressed: () {
            setState(() {
              heightOfModalBottomSheet += 10;
            });
          }),
        );
      });
});

Please note that the new setState will override your main widget setState but sure you can just rename it so you would be able to set state of your parent widget and the modal’s

showModalBottomSheet(
    context: context,
    builder: (context) {
      return StatefulBuilder(
          builder: (BuildContext context, StateSetter setState /*You can rename this!*/) {
        return Container(
          height: heightOfModalBottomSheet,
          child: RaisedButton(onPressed: () {
            setState(() {
              heightOfModalBottomSheet += 10;
            });
          }),
        );
      });
});

This was originally posted as an answer to a question on Stackoverflow but I think it’s worth sharing here also!

Blog DartFlutter

Post navigation

Previous post
Next post

Related Posts

Your Resume is Due for a Rewrite

September 5, 2023February 20, 2024

In today’s world, robots and automated systems quietly power much of our daily routines, often operating in the background without our awareness. One notable example of this is the Applicant Tracking System (ATS). It plays a crucial role in the initial stages of the hiring process, and surprisingly, it can…

Read More
Blog

Docker Compose Watch could be a life saver

January 29, 2024February 20, 2024

Spinning off a development environment with file watch capability is no longer a hassle. You can basically watch a directory and sync it with another one on the guest container even recompile your app if a certain file has been changed eg. package.json Maybe I will try this with the…

Read More

إن طابت النفوس وسع المكان

September 8, 2023February 20, 2024

أو كما نقول باللهجة السودانية لو النفوس اطايبت بتشيلنا

Read More
©2026 Mahgoub | WordPress Theme by SuperbThemes