반응형
다음 블로그를 참고했다.
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);
}
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
결과
종료 버튼을 누를 시 로딩페이지를 띄우지 않고 어플을 종료한다.
반응형
'앱 프로그래밍 > Flutter' 카테고리의 다른 글
[오류 해결]flutter: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 5082 pos 12: '!_debugLocked': is not true. (0) | 2022.02.14 |
---|---|
플러터로 기상청 날씨 앱 만들기 일지 8. 마무리 (1) | 2022.01.17 |
플러터로 기상청 날씨 앱 만들기 일지 7. 설정 페이지 추가 (0) | 2022.01.16 |
플러터로 기상청 날씨 앱 만들기 일지 6. 시간별 날씨, 3일간 오전/오후 날씨 아이콘 처리 (2) | 2022.01.16 |
플러터 DateFormat 요일 한국어로 출력 (0) | 2022.01.14 |
플러터로 기상청 날씨 앱 만들기 일지 5. 기상청 API 데이터 연동 오류 수정(HTTP service에러는 해결 불가능...) (2) | 2022.01.14 |