-
[Flutter]플러터 Back Key(빽키) 컨트롤하기 |안드로이드, IOSFlutter_끄적끄적 2021. 11. 27. 12:22반응형
- 사용된 패키지
import 'package:flutter/services.dart';
- 사용 코드(WillPopScope 위젯)
@override Widget build(BuildContext context) { _firstMainScreenProvider = Provider.of<FirstMainScreenProvider>(context); //WillPopScope는 사용자가 빽키를 눌렀을때 작동되는 위젯 return WillPopScope( onWillPop: () { return _onBackKey(); }, child: Scaffold( resizeToAvoidBottomInset: false, appBar: AppBar(
- 사용 코드(WillPopScope 에서 사용된 함수)
//휴대폰 피지컬 버튼 뒤로 가기 눌렀을때, Future<bool> _onBackKey() async { return await showDialog( context: context, builder: (BuildContext context) { return AlertDialog( backgroundColor: Color(0xff161619), title: Text( '끝내시겠습니까?', style: TextStyle(color: Colors.white), ), actions: [ TextButton( onPressed: () { //onWillpop에 true가 전달되어 앱이 종료 된다. Navigator.pop(context, true); }, child: Text('끝내기')), TextButton( onPressed: () { //onWillpop에 false 전달되어 앱이 종료되지 않는다. Navigator.pop(context, false); }, child: Text('아니요')), ], ); }); }
반응형'Flutter_끄적끄적' 카테고리의 다른 글
[Flutter]플러터(캘린더-각종 한국어 적용)|안드로이드, IOS (2) 2021.11.27 [Flutter]플러터 (앱 종료 함수) |안드로이드, IOS (0) 2021.11.27 [Flutter]플러터(MediaQuery 로딩 )|안드로이드, IOS (0) 2021.11.23 [Flutter]플러터 암/복호화(encrypt) |안드로이드, IOS (0) 2021.11.18 [Flutter]플러터 (공용 디렉토리 File 경로 읽기/쓰기) |안드로이드, IOS (0) 2021.11.18 - 사용된 패키지