본문 바로가기
Flutter

[Flutter] refresh data on pop ; 뒤로가기 후 새로 데이터 요청

by hymndaniel 2022. 5. 11.

Motivation

페이지를 이동하여 어떤 데이터를 수정하고나서 뒤로가기 버튼으로 이전 화면으로 돌아오면 수정된 데이터가 반영되게하고 싶음.

돌아오는 이벤트와 데이터를 요청하는 로직을 연결

 

아래처럼 push 뒤에 then 으로 수행하고 싶은 로직 추가

//Page1
    Navigator.push(context, MaterialPageRoute(builder: (context) => Page2())).then((value) {
                  setState(() {
                    // refresh state of Page1
                  });
                });

 

만약 이동하는 페이지가 여러개인 경우, 중간에 있는 페이지는 pop하도록 하여 처리하였음

// 중간에 있는 페이지
Navigator.push(
  context,
  MaterialPageRoute(
      builder: (context) => DetailPage(
            userId: userId,
            selectedDate: initDate,
          )),
).then((value) {
  Navigator.pop(context);
});

 

 

 

https://stackoverflow.com/questions/55769939/is-it-possible-to-refresh-or-reload-page-with-navigator-pop-like-1st-nav-pus

 

is it possible to refresh or reload page with navigator.pop... like 1st (nav.push=>2) page to 2nd page and back from 2nd (nav.po

I want to pass values from 2nd page to 1st page with navigator.pop and refresh or reload my 1st page with new values in initstate or any other work around? I am able to get these values in 1st page...

stackoverflow.com

 
 
728x90