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