-
[Flutter]플러터 (앱 종료 함수) |안드로이드, IOSFlutter_끄적끄적 2021. 11. 27. 12:26반응형
- 사용된 패키지
import 'package:flutter/services.dart';
- 사용 코드
appBar: AppBar( backgroundColor: Color(0xff161619), toolbarHeight: 28, //앱 종료 버튼 따로 만들기 leading: IconButton( icon: Icon(CupertinoIcons.power,size:20,), onPressed: () { _onPowerKey(); }, ),
- 사용 코드(SystemChannel)
//앱 내에서 종료 버튼 눌렀을때, Future _onPowerKey() async { return await showDialog( context: context, builder: (BuildContext context) { return AlertDialog( backgroundColor: Color(0xff161619), title: Text( '끝내시겠습니까?', style: TextStyle(color: Colors.white), ), actions: [ TextButton( onPressed: () { //아래 함수를 이용해서 앱을 종료 할 수 있다. SystemChannels.platform.invokeMethod('SystemNavigator.pop'); }, child: Text('끝내기')), TextButton( onPressed: () { Navigator.pop(context); }, child: Text('아니요')), ], ); }); }
반응형'Flutter_끄적끄적' 카테고리의 다른 글
[Flutter]플러터(폰트 고정)|안드로이드, IOS (0) 2021.11.27 [Flutter]플러터(캘린더-각종 한국어 적용)|안드로이드, IOS (2) 2021.11.27 [Flutter]플러터 Back Key(빽키) 컨트롤하기 |안드로이드, IOS (1) 2021.11.27 [Flutter]플러터(MediaQuery 로딩 )|안드로이드, IOS (0) 2021.11.23 [Flutter]플러터 암/복호화(encrypt) |안드로이드, IOS (0) 2021.11.18 - 사용된 패키지