@@ -9,6 +9,7 @@ import 'package:flood_mobile/Components/add_automatic_torrent.dart';
9
9
import 'package:flood_mobile/Components/logout_alert.dart' ;
10
10
import 'package:flood_mobile/Components/nav_drawer_list_tile.dart' ;
11
11
import 'package:flood_mobile/Components/notification_popup_dialogue_container.dart' ;
12
+ import 'package:flood_mobile/Components/toast_component.dart' ;
12
13
import 'package:flood_mobile/Constants/theme_provider.dart' ;
13
14
import 'package:flood_mobile/Pages/about_screen.dart' ;
14
15
import 'package:flood_mobile/Pages/settings_screen.dart' ;
@@ -20,6 +21,7 @@ import 'package:flood_mobile/Route/routes.dart';
20
21
import 'package:flutter/material.dart' ;
21
22
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart' ;
22
23
import 'package:flutter_svg/svg.dart' ;
24
+ import 'package:fluttertoast/fluttertoast.dart' ;
23
25
import 'package:font_awesome_flutter/font_awesome_flutter.dart' ;
24
26
import 'package:hidden_drawer_menu/controllers/simple_hidden_drawer_controller.dart' ;
25
27
import 'package:hidden_drawer_menu/simple_hidden_drawer/simple_hidden_drawer.dart' ;
@@ -45,6 +47,7 @@ class _HomeScreenState extends State<HomeScreen> {
45
47
File ? _file;
46
48
late String base64;
47
49
late String directoryDefault;
50
+ DateTime timeBackPressed = DateTime .now ();
48
51
49
52
@override
50
53
void initState () {
@@ -110,6 +113,20 @@ class _HomeScreenState extends State<HomeScreen> {
110
113
}
111
114
}
112
115
116
+ Future <bool > onBackPressed () async {
117
+ final differnce = DateTime .now ().difference (timeBackPressed);
118
+ final isExitWarning = differnce >= Duration (seconds: 2 );
119
+ timeBackPressed = DateTime .now ();
120
+
121
+ if (isExitWarning) {
122
+ Toasts .showExitWarningToast (msg: 'Press back button again to exit' );
123
+ return false ;
124
+ } else {
125
+ Fluttertoast .cancel ();
126
+ return true ;
127
+ }
128
+ }
129
+
113
130
@override
114
131
Widget build (BuildContext context) {
115
132
double wp = MediaQuery .of (context).size.width;
@@ -137,66 +154,69 @@ class _HomeScreenState extends State<HomeScreen> {
137
154
break ;
138
155
}
139
156
return Consumer <HomeProvider >(builder: (context, homeModel, child) {
140
- return Scaffold (
141
- appBar: AppBar (
142
- leading: IconButton (
143
- icon: Icon (
144
- Icons .menu,
145
- color: ThemeProvider .theme.textTheme.bodyText1? .color,
157
+ return WillPopScope (
158
+ onWillPop: onBackPressed,
159
+ child: Scaffold (
160
+ appBar: AppBar (
161
+ leading: IconButton (
162
+ icon: Icon (
163
+ Icons .menu,
164
+ color: ThemeProvider .theme.textTheme.bodyText1? .color,
165
+ ),
166
+ onPressed: () {
167
+ controller.toggle ();
168
+ },
146
169
),
147
- onPressed: () {
148
- controller.toggle ();
149
- },
150
- ),
151
- title: Image (
152
- key: Key ('Flood Icon' ),
153
- image: AssetImage (
154
- 'assets/images/icon.png' ,
170
+ title: Image (
171
+ key: Key ('Flood Icon' ),
172
+ image: AssetImage (
173
+ 'assets/images/icon.png' ,
174
+ ),
175
+ width: 60 ,
176
+ height: 60 ,
155
177
),
156
- width: 60 ,
157
- height: 60 ,
158
- ),
159
- centerTitle: true ,
160
- backgroundColor: Theme .of (context).primaryColor,
161
- elevation: 0 ,
162
- actions: [
163
- RSSFeedButtonWidget (),
164
- Badge (
165
- showBadge:
166
- homeModel.unreadNotifications == 0 ? false : true ,
167
- key: Key ('Badge Widget' ),
168
- badgeColor: Theme .of (context).accentColor,
169
- badgeContent: Center (
170
- child: Text (
171
- homeModel.unreadNotifications.toString (),
172
- style: TextStyle (color: Colors .white),
178
+ centerTitle: true ,
179
+ backgroundColor: Theme .of (context).primaryColor,
180
+ elevation: 0 ,
181
+ actions: [
182
+ RSSFeedButtonWidget (),
183
+ Badge (
184
+ showBadge:
185
+ homeModel.unreadNotifications == 0 ? false : true ,
186
+ key: Key ('Badge Widget' ),
187
+ badgeColor: Theme .of (context).colorScheme.secondary,
188
+ badgeContent: Center (
189
+ child: Text (
190
+ homeModel.unreadNotifications.toString (),
191
+ style: TextStyle (color: Colors .white),
192
+ ),
173
193
),
174
- ),
175
- position: BadgePosition (top: 0 , end: 3 ),
176
- child: IconButton (
177
- icon: Icon (
178
- Icons .notifications,
194
+ position: BadgePosition (top: 0 , end: 3 ),
195
+ child: IconButton (
196
+ icon: Icon (
197
+ Icons .notifications,
198
+ ),
199
+ onPressed: () {
200
+ showDialog (
201
+ context: context,
202
+ builder: (BuildContext context) {
203
+ return AlertDialog (
204
+ key: Key ('Notification Alert Dialog' ),
205
+ elevation: 0 ,
206
+ backgroundColor: Theme .of (context).primaryColor,
207
+ content: notificationPopupDialogueContainer (
208
+ context: context,
209
+ ),
210
+ );
211
+ },
212
+ );
213
+ },
179
214
),
180
- onPressed: () {
181
- showDialog (
182
- context: context,
183
- builder: (BuildContext context) {
184
- return AlertDialog (
185
- key: Key ('Notification Alert Dialog' ),
186
- elevation: 0 ,
187
- backgroundColor: Theme .of (context).primaryColor,
188
- content: notificationPopupDialogueContainer (
189
- context: context,
190
- ),
191
- );
192
- },
193
- );
194
- },
195
215
),
196
- ),
197
- ],
216
+ ],
217
+ ),
218
+ body: screenCurrent,
198
219
),
199
- body: screenCurrent,
200
220
);
201
221
});
202
222
},
0 commit comments