본문 바로가기
앱 프로그래밍/flutter

[플러터 기능 구현] loading 페이지를 거치지 않고 뒤로 가기

by 청량리 물냉면 2022. 2. 13.
반응형

다음 블로그를 참고했다.

 

https://fenderist.tistory.com/133

 

[Flutter] Back button으로 프로그램 종료처리하기

[Flutter] Back button으로 프로그램 종료처리하기 ​ 사내 업무 프로그램 개발을 하다가. Landing페이지를 띄운뒤에 메인페이지로 넘어 갔을때. Back 버튼을 누르면 Landing 페이지로 넘어 가게 되는 문제

fenderist.tistory.com

 

블로그의 글을 따라한 뒤 Future<bool> _onBackPressed() 부분에서 오류가 뜰 경우,

Future 함수 마지막 부분

 ) ??
        false;

을 

.then((value) => value ?? false);

로 고쳐준다.

 

 

전체 코드

Future<bool> _onBackPressed(){ //뒤로가기
  return showDialog(
    context: context,
    builder: (BuildContext context) => AlertDialog(
      title: Text("종료하시겠습니까?"),
      actions: <Widget>[
        ElevatedButton(
          child: Text("종료"),
          onPressed: () => Navigator.pop(context, true),
        ),
        ElevatedButton(
          child: Text("돌아가기"),
          onPressed: () => Navigator.pop(context, false),
        ),
      ],
    ),
  ).then((value) => value ?? false);
}

 

출처: https://stackoverflow.com/questions/68454245/flutter-a-value-of-type-futuredynamic-cant-be-returned-from-the-method-on

 

Flutter A value of type 'Future<dynamic>' can't be returned from the method '_onBackPress' because it has a return type of 'Futu

i am working on back button in my app but i face this issue in flutter Thank so much in advanced i am doing this before with this function but now it's not working i think because of null safty sor...

stackoverflow.com

 

 

결과

종료 버튼을 누를 시 로딩페이지를 띄우지 않고 어플을 종료한다.

반응형