0

I have Widget1 which opens up ModalBottomSheet. ModalBottomSheet contains TextField(EditText) & one button. User can input values to TextField that can make button enable/disable based on some validation. TextField is something customized component. This whole flow is made using dynamic forms. We are making use of streams to transfer TextField changes which are to be listened by Widget1(so that it can rebuild UI). But it seems when we have ModalBottomSheet on the screen the Widget1 is unable to listen to any change. If i am making use of simple widget instead of ModalBottomSheet then it works properly. On most of the blogs i found about "StatefulBuilder" inside ModalBottomSheet, but that will not solve this problem as it will be helpful if user is making any direct change inside ModalBottomSheet(like button click or so).

Please suggest some approach to resolve this issue.

user2050075
  • 189
  • 3
  • 14

1 Answers1

0

Have you tried to warp everything in a StatefulBuilder Widget inside the showModalBottomSheet() Function? I use it like this, which gives me the possibility to setState inside the ModalBottomSheet.

yourFunctionToShowModalBottomSheet(BuildContext ctx, [Other args]) {
  showModalBottomSheet(
    context: context,
    builder: (context) {
      return StatefulBuilder(
        builder: (ctx, StateSetter mySetState) {
          return YOURWIDGET()
        }
      )
    })
  )
}

This will give you the possibilty to setState (in this example with mySetState) within the ModalBottomSheet.

Severin13
  • 1
  • 3
  • Thanks for your response. Yes I have tried with StatefulBuilder. But that will not solve the purpose. It will be useful when we have some button or something inside the BottomSheet that will cause the state change. Here in my case the event when to update the state is with the Widget1(that has triggered BottomSheet). It seems Widget1 is not acting at all when BottomSheet is in foreground. – user2050075 Oct 28 '21 at 08:46
  • How about passing a function from Widget1 as argument to the Function that builds the ModalBottomSheet. And then trigger this functon within a button on the ModalBottomSheet? – Severin13 Oct 28 '21 at 09:32
  • The problem is similar to some API call on the parent widget. IN the meantime user has opened the bottomsheet. Now how t notify the bottom sheet about the result of api. I have used stream controller also to broadcast the result to bottom sheet. But it seems widget is not broadcasting result. – user2050075 Oct 28 '21 at 10:44