Skip to content

Commit 8df5618

Browse files
committed
update logout feature
1 parent 4e9df34 commit 8df5618

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

lib/main.dart

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import 'dart:io';
33

44
import 'package:cached_network_image/cached_network_image.dart';
55
import 'package:cloud_firestore/cloud_firestore.dart';
6+
import 'package:firebase_auth/firebase_auth.dart';
67
import 'package:flutter/material.dart';
78
import 'package:flutter_chat_demo/chat.dart';
89
import 'package:flutter_chat_demo/const.dart';
10+
import 'package:flutter_chat_demo/login.dart';
911
import 'package:flutter_chat_demo/settings.dart';
1012
import 'package:google_sign_in/google_sign_in.dart';
1113

@@ -39,7 +41,8 @@ class MainScreenState extends State<MainScreen> {
3941
context: context,
4042
builder: (BuildContext context) {
4143
return SimpleDialog(
42-
contentPadding: EdgeInsets.only(left: 0.0, right: 0.0, top: 0.0, bottom: 0.0),
44+
contentPadding:
45+
EdgeInsets.only(left: 0.0, right: 0.0, top: 0.0, bottom: 0.0),
4346
children: <Widget>[
4447
Container(
4548
color: themeColor,
@@ -58,7 +61,10 @@ class MainScreenState extends State<MainScreen> {
5861
),
5962
Text(
6063
'Exit app',
61-
style: TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold),
64+
style: TextStyle(
65+
color: Colors.white,
66+
fontSize: 18.0,
67+
fontWeight: FontWeight.bold),
6268
),
6369
Text(
6470
'Are you sure to exit app?',
@@ -82,7 +88,8 @@ class MainScreenState extends State<MainScreen> {
8288
),
8389
Text(
8490
'CANCEL',
85-
style: TextStyle(color: primaryColor, fontWeight: FontWeight.bold),
91+
style: TextStyle(
92+
color: primaryColor, fontWeight: FontWeight.bold),
8693
)
8794
],
8895
),
@@ -102,7 +109,8 @@ class MainScreenState extends State<MainScreen> {
102109
),
103110
Text(
104111
'YES',
105-
style: TextStyle(color: primaryColor, fontWeight: FontWeight.bold),
112+
style: TextStyle(
113+
color: primaryColor, fontWeight: FontWeight.bold),
106114
)
107115
],
108116
),
@@ -183,7 +191,8 @@ class MainScreenState extends State<MainScreen> {
183191
},
184192
color: greyColor2,
185193
padding: EdgeInsets.fromLTRB(25.0, 10.0, 25.0, 10.0),
186-
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
194+
shape:
195+
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
187196
),
188197
margin: EdgeInsets.only(bottom: 10.0, left: 5.0, right: 5.0),
189198
);
@@ -196,19 +205,27 @@ class MainScreenState extends State<MainScreen> {
196205
if (choice.title == 'Log out') {
197206
handleSignOut();
198207
} else {
199-
Navigator.push(context, MaterialPageRoute(builder: (context) => Settings()));
208+
Navigator.push(
209+
context, MaterialPageRoute(builder: (context) => Settings()));
200210
}
201211
}
202212

203213
Future<Null> handleSignOut() async {
204214
this.setState(() {
205215
isLoading = true;
206216
});
217+
218+
await FirebaseAuth.instance.signOut();
219+
await googleSignIn.disconnect();
207220
await googleSignIn.signOut();
221+
208222
this.setState(() {
209223
isLoading = false;
210224
});
211-
Navigator.pop(context);
225+
226+
Navigator.of(context).pushAndRemoveUntil(
227+
MaterialPageRoute(builder: (context) => MyApp()),
228+
(Route<dynamic> route) => false);
212229
}
213230

214231
@override
@@ -264,7 +281,8 @@ class MainScreenState extends State<MainScreen> {
264281
} else {
265282
return ListView.builder(
266283
padding: EdgeInsets.all(10.0),
267-
itemBuilder: (context, index) => buildItem(context, snapshot.data.documents[index]),
284+
itemBuilder: (context, index) =>
285+
buildItem(context, snapshot.data.documents[index]),
268286
itemCount: snapshot.data.documents.length,
269287
);
270288
}
@@ -277,7 +295,9 @@ class MainScreenState extends State<MainScreen> {
277295
child: isLoading
278296
? Container(
279297
child: Center(
280-
child: CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(themeColor)),
298+
child: CircularProgressIndicator(
299+
valueColor:
300+
AlwaysStoppedAnimation<Color>(themeColor)),
281301
),
282302
color: Colors.white.withOpacity(0.8),
283303
)

0 commit comments

Comments
 (0)