0

the setstate in bottomsheet is not working even using statefulwidget... i want to refresh the display of parent after popping bottomsheet

should i call setstate in void instead? how to do this ?

ElevatedButton(
             ...
   onPressed: () {
                  BottomSheet(context, id, expiry);
                  },
             ...
),


void BottomSheet(BuildContext context, String id, String expiry) {
  showModalBottomSheet(
    context: context,
    isScrollControlled: true,
    ....
        ),
      ),
      child: BottomSheetWidget(id, expiry),
    ),
  );
}


class BottomSheetWidget extends StatefulWidget {
  ....
}

class _BottomSheetWidgetState extends State<BottomSheetWidget> {
  ..
                onTap: () {
                  setState(() {
                    updated parent data here.....
                  });
                  Navigator.pop(context);
                  },
                ....
}
icantcode
  • 142
  • 1
  • 15
  • Can you include full sample widget? – Md. Yeasin Sheikh Apr 21 '22 at 18:59
  • Check this link maybe your problem is same. [refreshing a page on pop](https://stackoverflow.com/questions/71914371/how-to-reload-the-screen-in-flutter-on-alert-dialog-button-press/71914944#71914944) – R.Raman Apr 21 '22 at 19:05

2 Answers2

2

Try using MaterialPageRoute to rebuild the display of the parent page

onTap: () {
  setState(() {
     updated parent data here.....
   });
  Navigator.pushReplacement(
    context,
    MaterialPageRoute(builder: (context) => ParentScreen()),
  );
}
Samuel Olufemi
  • 715
  • 2
  • 12
1

Call .then method at the end of showModelBottomSheet()

 showModalBottomSheet(context: context, builder: builder).then((value) {
  setState(() {
    
  });
});
Pradeep
  • 21
  • 1
  • 2