Skip to content

Commit 906b85a

Browse files
Add Exit app dialog
1 parent 16adfa0 commit 906b85a

File tree

2 files changed

+70
-17
lines changed

2 files changed

+70
-17
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'package:emart/common_widgets/custom_button.dart';
2+
import 'package:emart/consts/consts.dart';
3+
import 'package:flutter/services.dart';
4+
5+
Widget exitDialog(context) {
6+
return Dialog(
7+
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
8+
child: Column(
9+
mainAxisSize: MainAxisSize.min,
10+
children: [
11+
"Want to exit App?".text.size(18).color(darkFontGrey).make(),
12+
10.heightBox,
13+
Row(
14+
children: [
15+
Expanded(
16+
child: customButton(
17+
title: "Yes",
18+
color: redColor,
19+
onPressed: () => SystemNavigator.pop(),
20+
textColor: whiteColor,
21+
),
22+
),
23+
const SizedBox(width: 30),
24+
Expanded(
25+
child: customButton(
26+
title: "No",
27+
color: darkFontGrey,
28+
onPressed: () => Navigator.of(context).pop(),
29+
textColor: whiteColor,
30+
),
31+
),
32+
],
33+
),
34+
],
35+
)
36+
.box
37+
.rounded
38+
.color(lightGrey)
39+
.padding(const EdgeInsets.symmetric(horizontal: 20, vertical: 30))
40+
.make(),
41+
);
42+
}

lib/views/home_view/home.dart

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// ignore_for_file: must_be_immutable
22

3+
import 'package:emart/common_widgets/exit_dialog.dart';
34
import 'package:emart/consts/consts.dart';
45
import 'package:emart/views/cart_screen_view/cart_screen.dart';
56
import 'package:emart/views/category_screen_view/category_screen.dart';
@@ -32,25 +33,35 @@ class Home extends StatelessWidget {
3233

3334
@override
3435
Widget build(BuildContext context) {
35-
return Scaffold(
36-
body: Column(
37-
children: [
38-
Obx(
39-
() => Expanded(
40-
child: navBody.elementAt(controller.currentNavIndex.value),
36+
return WillPopScope(
37+
onWillPop: () async {
38+
showDialog(
39+
context: context,
40+
barrierDismissible: false,
41+
builder: (context) => exitDialog(context),
42+
);
43+
return false;
44+
},
45+
child: Scaffold(
46+
body: Column(
47+
children: [
48+
Obx(
49+
() => Expanded(
50+
child: navBody.elementAt(controller.currentNavIndex.value),
51+
),
4152
),
53+
],
54+
),
55+
bottomNavigationBar: Obx(
56+
() => BottomNavigationBar(
57+
currentIndex: controller.currentNavIndex.value,
58+
type: BottomNavigationBarType.fixed,
59+
selectedLabelStyle: const TextStyle(fontFamily: semibold),
60+
selectedItemColor: redColor,
61+
items: navbarItems,
62+
backgroundColor: whiteColor,
63+
onTap: (newIndex) => controller.currentNavIndex.value = newIndex,
4264
),
43-
],
44-
),
45-
bottomNavigationBar: Obx(
46-
() => BottomNavigationBar(
47-
currentIndex: controller.currentNavIndex.value,
48-
type: BottomNavigationBarType.fixed,
49-
selectedLabelStyle: const TextStyle(fontFamily: semibold),
50-
selectedItemColor: redColor,
51-
items: navbarItems,
52-
backgroundColor: whiteColor,
53-
onTap: (newIndex) => controller.currentNavIndex.value = newIndex,
5465
),
5566
),
5667
);

0 commit comments

Comments
 (0)