showModalBottomSheet refresh patent view

400 views
Skip to first unread message

Igor Karelin

unread,
Apr 30, 2020, 10:41:51 PM4/30/20
to Flutter Development (flutter-dev)
I have a view which opening a ModalBottomSheet.
How can I refresh a parent controller state when the sheet is closing ?
From the modal sheet I'm adding/changing data in sqflite, and I need the way to refresh the data in parent view with the updated values.

Suzuki Tomohiro

unread,
Apr 30, 2020, 11:40:26 PM4/30/20
to Flutter Development (flutter-dev)
How about passing a ValueNotifier from the parent to the ModalBottomSheet?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/7c4144aa-aacf-4ab9-ad3c-a6a90a90ec28%40googlegroups.com.

Igor Karelin

unread,
May 9, 2020, 6:33:21 AM5/9/20
to Suzuki Tomohiro, Flutter Development (flutter-dev)
I’ve found a simple solution:

2-nd Page:

// sending "Bar" from 2nd
Navigator.pop(context, "Bar");

1-st Page:

// receiving "Bar" in 1st
String received = await Navigator.push(context, MaterialPageRoute(builder: (_) => Page2("Foo")));

So I receiving the String in the 1st controller and can execute the code regarding the ‘answer’ from the modal view.

Best regards, Igor Karelin
Flutter Developer on freelance

Riswan

unread,
May 9, 2020, 7:17:14 AM5/9/20
to Igor Karelin, Flutter Development (flutter-dev), Suzuki Tomohiro
Hi,

I think your controller calls every time that class loaded and it will unnecessarily waiting for something if you are coming from other places. Can’t you use popAndPushNamed in the second page,

Navigator.popAndPushNamed(comentext, '/page1');

Thanks
Riswan MSM

--
Riswan

Igor Karelin

unread,
May 9, 2020, 7:25:52 AM5/9/20
to Riswan, Flutter Development (flutter-dev), Suzuki Tomohiro
So this way I’ll dismiss a modal (second) controller and execute initState in the first controller (i. e. fully load parent controller) ?

Best regards, Igor Karelin
Flutter Developer on freelance

Riswan

unread,
May 9, 2020, 7:43:03 AM5/9/20
to Igor Karelin, Flutter Development (flutter-dev), Suzuki Tomohiro
Yes you are correct, your solution might fit that scenario.
--
Riswan

Igor Karelin

unread,
May 9, 2020, 7:48:35 AM5/9/20
to Riswan, Flutter Development (flutter-dev), Suzuki Tomohiro
Thank you, I’ll give it a try. :)

Best regards, Igor Karelin
Flutter Developer on freelance
Reply all
Reply to author
Forward
0 new messages