Skip to content

Commit 9c23511

Browse files
committed
♻️ code refactor
1.:recycle: Google login button moved to seperate widget. 2.:bug:(fix) Username text overflow error.
1 parent d38053e commit 9c23511

File tree

13 files changed

+259
-239
lines changed

13 files changed

+259
-239
lines changed

lib/page/Auth/signin.dart

Lines changed: 37 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_twitter_clone/helper/theme.dart';
33
import 'package:flutter_twitter_clone/helper/utility.dart';
4+
import 'package:flutter_twitter_clone/page/Auth/widget/googleLoginButton.dart';
45
import 'package:flutter_twitter_clone/state/authState.dart';
56
import 'package:flutter_twitter_clone/widgets/customWidgets.dart';
67
import 'package:flutter_twitter_clone/widgets/newWidget/customLoader.dart';
@@ -24,36 +25,46 @@ class _SignInState extends State<SignIn> {
2425
void initState() {
2526
_emailController = TextEditingController();
2627
_passwordController = TextEditingController();
27-
// _emailController.text = '[email protected]';
28-
// _passwordController.text = '1234567';
2928
loader = CustomLoader();
3029
super.initState();
3130
}
32-
31+
@override
32+
void dispose() {
33+
_emailController.dispose();
34+
_passwordController.dispose();
35+
super.dispose();
36+
}
3337
Widget _body(BuildContext context) {
3438
return SingleChildScrollView(
3539
child: Container(
36-
padding: EdgeInsets.symmetric(horizontal: 30),
37-
child: Column(
38-
mainAxisAlignment: MainAxisAlignment.start,
39-
crossAxisAlignment: CrossAxisAlignment.center,
40-
children: <Widget>[
41-
SizedBox(height: 150),
42-
_entryFeild('Enter email', controller: _emailController),
43-
_entryFeild('Enter password',
44-
controller: _passwordController, isPassword: true),
45-
_emailLoginButton(context),
46-
SizedBox(
47-
height: 20,
48-
),
49-
_labelButton('Forget password?', onPressed: () {
50-
Navigator.of(context).pushNamed('/ForgetPasswordPage');
51-
}),
52-
Divider(),
53-
_googleLoginButton(context),
54-
SizedBox(height: 100),
55-
],
56-
)),
40+
padding: EdgeInsets.symmetric(horizontal: 30),
41+
child: Column(
42+
mainAxisAlignment: MainAxisAlignment.start,
43+
crossAxisAlignment: CrossAxisAlignment.center,
44+
children: <Widget>[
45+
SizedBox(height: 150),
46+
_entryFeild('Enter email', controller: _emailController),
47+
_entryFeild('Enter password',
48+
controller: _passwordController, isPassword: true),
49+
_emailLoginButton(context),
50+
SizedBox(height: 20),
51+
_labelButton('Forget password?', onPressed: () {
52+
Navigator.of(context).pushNamed('/ForgetPasswordPage');
53+
}),
54+
Divider(
55+
height: 30,
56+
),
57+
SizedBox(
58+
height: 30,
59+
),
60+
GoogleLoginButton(
61+
loginCallback: widget.loginCallback,
62+
loader: loader,
63+
),
64+
SizedBox(height: 100),
65+
],
66+
),
67+
),
5768
);
5869
}
5970

@@ -110,46 +121,13 @@ class _SignInState extends State<SignIn> {
110121
color: TwitterColor.dodgetBlue,
111122
onPressed: _emailLogin,
112123
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 10),
113-
child: TitleText('Email Login', color: Colors.white),
114-
),
115-
);
116-
}
117-
118-
Widget _googleLoginButton(BuildContext context) {
119-
return Container(
120-
alignment: Alignment.center,
121-
margin: EdgeInsets.symmetric(vertical: 35),
122-
child: Row(
123-
mainAxisAlignment: MainAxisAlignment.center,
124-
children: <Widget>[
125-
MaterialButton(
126-
elevation: 2,
127-
shape: RoundedRectangleBorder(
128-
borderRadius: BorderRadius.circular(10)),
129-
color: Colors.white,
130-
onPressed: _googleLogin,
131-
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 10),
132-
child: Row(
133-
children: <Widget>[
134-
Image.asset(
135-
'assets/images/google_logo.png',
136-
height: 20,
137-
width: 20,
138-
),
139-
SizedBox(width: 10),
140-
TitleText(
141-
'Continue with Google',
142-
color: Colors.black54,
143-
),
144-
],
145-
)),
146-
],
124+
child: TitleText('Submit', color: Colors.white),
147125
),
148126
);
149127
}
150128

151129
void _emailLogin() {
152-
var state = Provider.of<AuthState>(context,listen: false);
130+
var state = Provider.of<AuthState>(context, listen: false);
153131
if (state.isbusy) {
154132
return;
155133
}
@@ -175,25 +153,6 @@ class _SignInState extends State<SignIn> {
175153
}
176154
}
177155

178-
void _googleLogin() {
179-
var state = Provider.of<AuthState>(context,listen: false);
180-
if (state.isbusy) {
181-
return;
182-
}
183-
loader.showLoader(context);
184-
state.handleGoogleSignIn().then((status) {
185-
// print(status)
186-
if (state.user != null) {
187-
loader.hideLoader();
188-
Navigator.pop(context);
189-
widget.loginCallback();
190-
} else {
191-
loader.hideLoader();
192-
cprint('Unable to login', errorIn: '_googleLoginButton');
193-
}
194-
});
195-
}
196-
197156
@override
198157
Widget build(BuildContext context) {
199158
return Scaffold(

lib/page/Auth/signup.dart

Lines changed: 43 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import 'package:flutter_twitter_clone/helper/enum.dart';
55
import 'package:flutter_twitter_clone/helper/theme.dart';
66
import 'package:flutter_twitter_clone/helper/utility.dart';
77
import 'package:flutter_twitter_clone/model/user.dart';
8+
import 'package:flutter_twitter_clone/page/Auth/widget/googleLoginButton.dart';
89
import 'package:flutter_twitter_clone/state/authState.dart';
910
import 'package:flutter_twitter_clone/widgets/customWidgets.dart';
1011
import 'package:flutter_twitter_clone/widgets/newWidget/customLoader.dart';
12+
import 'package:flutter_twitter_clone/widgets/newWidget/rippleButton.dart';
1113
import 'package:flutter_twitter_clone/widgets/newWidget/title_text.dart';
1214
import 'package:provider/provider.dart';
1315

@@ -22,7 +24,6 @@ class Signup extends StatefulWidget {
2224
class _SignupState extends State<Signup> {
2325
TextEditingController _nameController;
2426
TextEditingController _emailController;
25-
// TextEditingController _mobileController;
2627
TextEditingController _passwordController;
2728
TextEditingController _confirmController;
2829
CustomLoader loader;
@@ -33,18 +34,17 @@ class _SignupState extends State<Signup> {
3334
loader = CustomLoader();
3435
_nameController = TextEditingController();
3536
_emailController = TextEditingController();
36-
// _mobileController = TextEditingController();
3737
_passwordController = TextEditingController();
3838
_confirmController = TextEditingController();
39-
// _emailController.text = '[email protected]';
40-
// _passwordController.text = '1234567';
41-
// _nameController.text = 'Bruce Wayne';
42-
// _mobileController.text = '9871234567';
43-
// _passwordController.text = '1234567';
44-
// _confirmController.text = '1234567';
4539
super.initState();
4640
}
47-
41+
void dispose() {
42+
_emailController.dispose();
43+
_passwordController.dispose();
44+
_nameController.dispose();
45+
_confirmController.dispose();
46+
super.dispose();
47+
}
4848
Widget _body(BuildContext context) {
4949
return Container(
5050
height: fullHeight(context) - 88,
@@ -64,8 +64,14 @@ class _SignupState extends State<Signup> {
6464
controller: _confirmController, isPassword: true),
6565
_submitButton(context),
6666

67-
Divider(),
68-
_googleLoginButton(context)
67+
Divider(height: 30),
68+
SizedBox(height: 30),
69+
// _googleLoginButton(context),
70+
GoogleLoginButton(
71+
loginCallback: widget.loginCallback,
72+
loader: loader,
73+
),
74+
SizedBox(height: 30),
6975
],
7076
),
7177
),
@@ -117,41 +123,34 @@ class _SignupState extends State<Signup> {
117123
);
118124
}
119125

120-
Widget _googleLoginButton(BuildContext context) {
121-
return Container(
122-
alignment: Alignment.center,
123-
margin: EdgeInsets.symmetric(vertical: 35),
124-
child: Row(
125-
mainAxisAlignment: MainAxisAlignment.center,
126-
children: <Widget>[
127-
MaterialButton(
128-
elevation: 2,
129-
shape:
130-
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
131-
color: Colors.white,
132-
onPressed: _googleLogin,
133-
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 10),
134-
child: Row(
135-
children: <Widget>[
136-
Image.asset(
137-
'assets/images/google_logo.png',
138-
height: 20,
139-
width: 20,
140-
),
141-
SizedBox(width: 10),
142-
TitleText(
143-
'Continue with Google',
144-
color: Colors.black54,
145-
),
146-
],
147-
),
148-
),
149-
],
150-
),
151-
);
126+
void _googleLogin() {
127+
var state = Provider.of<AuthState>(context, listen: false);
128+
if (state.isbusy) {
129+
return;
130+
}
131+
loader.showLoader(context);
132+
state.handleGoogleSignIn().then((status) {
133+
// print(status)
134+
if (state.user != null) {
135+
loader.hideLoader();
136+
Navigator.pop(context);
137+
widget.loginCallback();
138+
} else {
139+
loader.hideLoader();
140+
cprint('Unable to login', errorIn: '_googleLoginButton');
141+
}
142+
});
152143
}
153144

154145
void _submitForm() {
146+
if (_emailController.text.isEmpty) {
147+
customSnackBar(_scaffoldKey, 'Please enter name');
148+
return;
149+
}
150+
if (_emailController.text.length > 27) {
151+
customSnackBar(_scaffoldKey, 'Name length cannot exceed 27 character');
152+
return;
153+
}
155154
if (_emailController.text == null ||
156155
_emailController.text.isEmpty ||
157156
_passwordController.text == null ||
@@ -164,6 +163,7 @@ class _SignupState extends State<Signup> {
164163
_scaffoldKey, 'Password and confirm password did not match');
165164
return;
166165
}
166+
167167
loader.showLoader(context);
168168
var state = Provider.of<AuthState>(context, listen: false);
169169
Random random = new Random();
@@ -199,25 +199,6 @@ class _SignupState extends State<Signup> {
199199
);
200200
}
201201

202-
void _googleLogin() {
203-
var state = Provider.of<AuthState>(context,listen: false);
204-
if (state.isbusy) {
205-
return;
206-
}
207-
loader.showLoader(context);
208-
state.handleGoogleSignIn().then((status) {
209-
// print(status)
210-
if (state.user != null) {
211-
loader.hideLoader();
212-
Navigator.pop(context);
213-
widget.loginCallback();
214-
} else {
215-
loader.hideLoader();
216-
cprint('Unable to login', errorIn: '_googleLoginButton');
217-
}
218-
});
219-
}
220-
221202
@override
222203
Widget build(BuildContext context) {
223204
return Scaffold(
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_twitter_clone/helper/utility.dart';
3+
import 'package:flutter_twitter_clone/state/authState.dart';
4+
import 'package:flutter_twitter_clone/widgets/newWidget/customLoader.dart';
5+
import 'package:flutter_twitter_clone/widgets/newWidget/rippleButton.dart';
6+
import 'package:flutter_twitter_clone/widgets/newWidget/title_text.dart';
7+
import 'package:provider/provider.dart';
8+
9+
class GoogleLoginButton extends StatelessWidget {
10+
const GoogleLoginButton({Key key, @required this.loader, this.loginCallback});
11+
final CustomLoader loader;
12+
final Function loginCallback;
13+
void _googleLogin(context) {
14+
var state = Provider.of<AuthState>(context, listen: false);
15+
loader.showLoader(context);
16+
state.handleGoogleSignIn().then((status) {
17+
// print(status)
18+
if (state.user != null) {
19+
loader.hideLoader();
20+
Navigator.pop(context);
21+
loginCallback();
22+
} else {
23+
loader.hideLoader();
24+
cprint('Unable to login', errorIn: '_googleLoginButton');
25+
}
26+
});
27+
}
28+
29+
@override
30+
Widget build(BuildContext context) {
31+
return RippleButton(
32+
onPressed: (){
33+
_googleLogin(context);
34+
},
35+
borderRadius: BorderRadius.circular(10),
36+
child: Container(
37+
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
38+
decoration: BoxDecoration(
39+
color: Colors.white,
40+
borderRadius: BorderRadius.circular(10),
41+
boxShadow: <BoxShadow>[
42+
BoxShadow(
43+
color: Color(0xffeeeeee),
44+
blurRadius: 15,
45+
offset: Offset(5, 5),
46+
),
47+
],
48+
),
49+
child: Wrap(
50+
children: <Widget>[
51+
Image.asset(
52+
'assets/images/google_logo.png',
53+
height: 20,
54+
width: 20,
55+
),
56+
SizedBox(width: 10),
57+
TitleText(
58+
'Continue with Google',
59+
color: Colors.black54,
60+
),
61+
],
62+
),
63+
),
64+
);
65+
}
66+
}

0 commit comments

Comments
 (0)