Home > Enterprise >  set state not working for modal bottom sheet,
set state not working for modal bottom sheet,

Time:03-11

I have a button that loads the image in container but set state doesn't update the state of bottom sheet. any help would be appreciated

CodePudding user response:

Return a stateful builder in bottom sheet and you can set state.

Color bottomSheetColor = Colors.green;

showBottomSheet(
context: context,
builder: (context) {
  return StatefulBuilder(
      builder: (context, setState) {
    return Container(
      color:bottomSheetColor,
      child: RaisedButton(onPressed: () {
        setState(() {
          bottomSheetColor = Colors.red;
        });
      }),
    );
  });
});

CodePudding user response:

Make sure the value you want to change is outside the Widget.

  • Related