Skip to content

Commit acfd477

Browse files
committed
Added signout button and loading spinner during animation
1 parent e2e82c3 commit acfd477

File tree

7 files changed

+133
-62
lines changed

7 files changed

+133
-62
lines changed

Diff for: assets/images/google_icon.png

4.63 KB
Loading

Diff for: lib/main.dart

+3-41
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import 'package:com_huthaifa_glints/screens/login/login_screen.dart';
22
import 'package:firebase_core/firebase_core.dart';
33
import 'package:flutter/material.dart';
44
import 'package:provider/provider.dart';
5-
65
import 'provider/login_provider.dart';
6+
import 'screens/homepage/homepage.dart';
77

88
void main() async {
99
WidgetsFlutterBinding.ensureInitialized();
1010
await Firebase.initializeApp();
11-
print('💪🐘💪 GLINTSARS... WE GOT THIS 💪🐘💪');
11+
print('💪🌟💪 GLINTSARS... WE GOT THIS 💪🌟💪');
1212
runApp(MyApp());
1313
}
1414

@@ -24,52 +24,14 @@ class MyApp extends StatelessWidget {
2424
primarySwatch: Colors.blue,
2525
),
2626
home: Consumer<LoginState>(builder: (context, loginState, __) {
27-
return loginState.isSignedIn ? MyHomePage(title: 'Huthaifa\'s Twitter Clone') : LoginPage();
27+
return loginState.isSignedIn ? HomePage(title: 'Huthaifa\'s Twitter Clone') : LoginPage();
2828
}),
2929
onGenerateRoute: (RouteSettings settings) {
3030
Map<dynamic, dynamic> routes = {};
3131
WidgetBuilder builder = routes[settings.name]!;
32-
3332
return MaterialPageRoute(builder: (ctx) => builder(ctx));
3433
},
3534
),
3635
);
3736
}
3837
}
39-
40-
class MyHomePage extends StatefulWidget {
41-
MyHomePage({Key? key, this.title}) : super(key: key);
42-
43-
final String? title;
44-
45-
@override
46-
_MyHomePageState createState() => _MyHomePageState();
47-
}
48-
49-
class _MyHomePageState extends State<MyHomePage> {
50-
@override
51-
Widget build(BuildContext context) {
52-
return Scaffold(
53-
appBar: AppBar(
54-
title: Text(widget.title!),
55-
),
56-
body: Center(
57-
child: Column(
58-
mainAxisAlignment: MainAxisAlignment.center,
59-
children: <Widget>[
60-
Text(
61-
'Welcome to twitter',
62-
),
63-
],
64-
),
65-
),
66-
floatingActionButton: FloatingActionButton(
67-
onPressed: () {},
68-
tooltip: "Create Tweet",
69-
child: Icon(
70-
Icons.add_circle,
71-
semanticLabel: "Create Tweet",
72-
)), // This trailing comma makes auto-formatting nicer for build methods.
73-
);
74-
}
75-
}

Diff for: lib/provider/login_provider.dart

+2
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ class LoginState extends ChangeNotifier {
2121

2222
void signOut() async {
2323
await LoginFunctions().signOut();
24+
_isSignedIn = false;
25+
notifyListeners();
2426
}
2527
}

Diff for: lib/screens/homepage/drawer_widget.dart

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'package:com_huthaifa_glints/provider/login_provider.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:provider/provider.dart';
4+
5+
class DrawerWidget extends StatelessWidget {
6+
@override
7+
Widget build(BuildContext context) {
8+
final _loginState = Provider.of<LoginState>(context, listen: true);
9+
return Container(
10+
width: MediaQuery.of(context).size.width * .65,
11+
color: Colors.grey.shade600,
12+
child: ListView(
13+
children: [
14+
Container(
15+
child: _loginState.isSignedIn
16+
? Column(
17+
children: [
18+
Container(
19+
margin: EdgeInsets.all(8),
20+
child: CircleAvatar(backgroundImage: NetworkImage(_loginState.user.image)),
21+
),
22+
Text(
23+
_loginState.user.userName,
24+
style: TextStyle(
25+
color: Colors.white,
26+
fontFamily: 'Gilroy',
27+
),
28+
),
29+
Text(
30+
'@' + _loginState.user.nickName,
31+
style: TextStyle(
32+
color: Colors.white,
33+
fontFamily: 'Gilroy',
34+
),
35+
),
36+
Text(
37+
_loginState.user.email,
38+
style: TextStyle(
39+
color: Colors.white,
40+
fontFamily: 'Gilroy',
41+
),
42+
),
43+
],
44+
)
45+
: Text(
46+
'Account',
47+
style: TextStyle(
48+
color: Colors.white,
49+
fontSize: 30,
50+
),
51+
),
52+
),
53+
ListTile(
54+
onTap: () {
55+
_loginState.signOut();
56+
Navigator.of(context).pop();
57+
},
58+
leading: Icon(
59+
Icons.logout,
60+
color: Colors.white,
61+
),
62+
title: Text("Logout", style: TextStyle(color: Colors.black)),
63+
)
64+
],
65+
),
66+
);
67+
}
68+
}

Diff for: lib/screens/homepage/homepage.dart

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:com_huthaifa_glints/screens/homepage/drawer_widget.dart';
2+
import 'package:flutter/material.dart';
3+
4+
class HomePage extends StatefulWidget {
5+
HomePage({Key? key, this.title}) : super(key: key);
6+
7+
final String? title;
8+
9+
@override
10+
_HomePageState createState() => _HomePageState();
11+
}
12+
13+
class _HomePageState extends State<HomePage> {
14+
@override
15+
Widget build(BuildContext context) {
16+
return Scaffold(
17+
drawer: DrawerWidget(),
18+
appBar: AppBar(
19+
title: Text(widget.title!),
20+
),
21+
body: Center(
22+
child: Column(
23+
mainAxisAlignment: MainAxisAlignment.center,
24+
children: <Widget>[
25+
Text(
26+
'Welcome to twitter',
27+
),
28+
],
29+
),
30+
),
31+
floatingActionButton: FloatingActionButton(
32+
onPressed: () {},
33+
tooltip: "Create Tweet",
34+
child: Icon(
35+
Icons.add_circle,
36+
semanticLabel: "Create Tweet",
37+
)), // This trailing comma makes auto-formatting nicer for build methods.
38+
);
39+
}
40+
}

Diff for: lib/screens/login/google_signin_btn__widget.dart

+18-19
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,32 @@ import 'package:com_huthaifa_glints/provider/login_provider.dart';
22
import 'package:flutter/material.dart';
33
import 'package:provider/provider.dart';
44

5-
class GoogleSigninButton extends StatefulWidget {
5+
class GoogleSigninButton extends StatelessWidget {
66
const GoogleSigninButton({Key? key}) : super(key: key);
77

8-
@override
9-
_GoogleSigninButtonState createState() => _GoogleSigninButtonState();
10-
}
11-
12-
class _GoogleSigninButtonState extends State<GoogleSigninButton> {
138
@override
149
Widget build(BuildContext context) {
1510
final _loginState = Provider.of<LoginState>(context, listen: true);
1611

1712
return !_loginState.isSignedIn
18-
? GestureDetector(
19-
onTap: () => _loginState.googleSignIn(),
20-
child: Container(
21-
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
22-
height: 50,
23-
width: 280,
24-
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
25-
child: ListTile(
26-
leading: Container(
27-
margin: EdgeInsets.fromLTRB(0, 7, 0, 12),
28-
child: Image.asset("assets/images/google_icon.png"),
13+
? _loginState.isSigningIn
14+
? CircularProgressIndicator()
15+
: GestureDetector(
16+
onTap: () => _loginState.googleSignIn(),
17+
child: Container(
18+
margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
19+
height: 50,
20+
width: 280,
21+
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
22+
child: ListTile(
23+
leading: Container(
24+
margin: EdgeInsets.fromLTRB(0, 7, 0, 12),
25+
child: Image.asset("assets/images/google_icon.png"),
26+
),
27+
title: Text('Sign in with Google', textAlign: TextAlign.center),
2928
),
30-
title: Text('Sign in with Google', textAlign: TextAlign.center),
31-
)))
29+
),
30+
)
3231
: ElevatedButton(
3332
child: Text('Tap to Logout'),
3433
onPressed: () => _loginState.signOut(),

Diff for: pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ flutter:
4444
# the material Icons class.
4545
uses-material-design: true
4646
# To add assets to your application, add an assets section, like this:
47-
# assets:
48-
# - images/a_dot_burr.jpeg
47+
assets:
48+
- assets/images/google_icon.png
4949
# - images/a_dot_ham.jpeg
5050
# An image asset can refer to one or more resolution-specific "variants", see
5151
# https://flutter.dev/assets-and-images/#resolution-aware.

0 commit comments

Comments
 (0)