Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- Hello World
- CrossAxisAlignment
- Column Widget
- listview
- flutter
- Load Image
- node.js
- Row Widget
- Flutter 예제
- InkWell
- Flutter Example
- Networking
- HTTP
- Flutter 강좌
- Flutter Tutorial
- Flutter 앱 배포
- MainAxisAlignment
- Cached Image
- Snackbar
- ListTile
- Row
- AppBar
- ListView.builder
- Image.network
- 반석천
- sqlite
- WillPopScope
- FutureBuilder
- navigator
- Scaffold
Archives
- Today
- Total
꿈꾸는 시스템 디자이너
Flutter Example - WillPopScope | Handel back button pressed 본문
Tutorial/Flutter with App
Flutter Example - WillPopScope | Handel back button pressed
독행소년 2019. 9. 27. 10:13import 'package:flutter/material.dart';
class WillPopScopeDemo extends StatelessWidget {
DateTime currentBackPressTime;
final scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
bool result = onPressBackButton();
return await Future.value(result);
},
child: Scaffold(
key: scaffoldKey,
appBar: AppBar(title: Text("WillPopScope Demo")),
body: Center(
child: Text("Tap back button to leave this page"),
),
),
);
}
bool onPressBackButton() {
DateTime now = DateTime.now();
if (currentBackPressTime == null ||
now.difference(currentBackPressTime) > Duration(seconds: 2)) {
currentBackPressTime = now;
scaffoldKey.currentState
..hideCurrentSnackBar()
..showSnackBar(SnackBar(
content: Text("Tap back again to leave."),
));
return false;
}
return true;
}
}
▶ Go to Table of Contents | 강의 목차로 이동
※ This example is also available in the Flutter Code Examples app. | 본 예제는 Flutter Code Examples 앱에서도 제공됩니다.
'Tutorial > Flutter with App' 카테고리의 다른 글
Flutter Example - ListView | basic (0) | 2019.09.27 |
---|---|
Flutter Example - Screen Management | Kept On Screen (0) | 2019.09.27 |
Flutter Example - AlertDialog (0) | 2019.09.27 |
Flutter Example - Navigation & routing | Return data from a screen (0) | 2019.09.27 |
Flutter Example - Navigation & routing | Send data to a new screen (0) | 2019.09.27 |
Comments