Skip to content

Commit 385b883

Browse files
committed
🗑 Remove deprecate code.
✏️ Fix typo
1 parent 81363a1 commit 385b883

15 files changed

+90
-102
lines changed

.vscode/settings.json

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2-
"cSpell.words": [
3-
"Alives",
4-
"Fwitter",
5-
"parentkey",
6-
"Retwetkey",
7-
"RGBO",
8-
"userlist"
9-
]
10-
}
2+
"cSpell.words": [
3+
"Alives",
4+
"Fwitter",
5+
"parentkey",
6+
"Retwetkey",
7+
"RGBO",
8+
"thumbpin",
9+
"userlist"
10+
]
11+
}

lib/helper/utility.dart

+10-13
Original file line numberDiff line numberDiff line change
@@ -198,32 +198,29 @@ class Utility {
198198
}
199199

200200
static bool validateCredentials(
201-
GlobalKey<ScaffoldState> _scaffoldKey, String? email, String? password) {
201+
BuildContext context, String? email, String? password) {
202202
if (email == null || email.isEmpty) {
203-
customSnackBar(_scaffoldKey, 'Please enter email id');
203+
customSnackBar(context, 'Please enter email id');
204204
return false;
205205
} else if (password == null || password.isEmpty) {
206-
customSnackBar(_scaffoldKey, 'Please enter password');
206+
customSnackBar(context, 'Please enter password');
207207
return false;
208208
} else if (password.length < 8) {
209-
customSnackBar(_scaffoldKey, 'Password must me 8 character long');
209+
customSnackBar(context, 'Password must me 8 character long');
210210
return false;
211211
}
212212

213213
var status = validateEmail(email);
214214
if (!status) {
215-
customSnackBar(_scaffoldKey, 'Please enter valid email id');
215+
customSnackBar(context, 'Please enter valid email id');
216216
return false;
217217
}
218218
return true;
219219
}
220220

221-
static customSnackBar(GlobalKey<ScaffoldState>? _scaffoldKey, String msg,
221+
static customSnackBar(BuildContext context, String msg,
222222
{double height = 30, Color backgroundColor = Colors.black}) {
223-
if (_scaffoldKey == null || _scaffoldKey.currentState == null) {
224-
return;
225-
}
226-
_scaffoldKey.currentState!.hideCurrentSnackBar();
223+
ScaffoldMessenger.of(context).hideCurrentSnackBar();
227224
final snackBar = SnackBar(
228225
backgroundColor: backgroundColor,
229226
content: Text(
@@ -233,7 +230,7 @@ class Utility {
233230
),
234231
),
235232
);
236-
_scaffoldKey.currentState!.showSnackBar(snackBar);
233+
ScaffoldMessenger.of(context).showSnackBar(snackBar);
237234
}
238235

239236
static bool validateEmail(String email) {
@@ -281,13 +278,13 @@ class Utility {
281278
}
282279

283280
static void copyToClipBoard({
284-
required GlobalKey<ScaffoldState> scaffoldKey,
281+
required BuildContext context,
285282
required String text,
286283
required String message,
287284
}) {
288285
var data = ClipboardData(text: text);
289286
Clipboard.setData(data);
290-
customSnackBar(scaffoldKey, message);
287+
customSnackBar(context, message);
291288
}
292289

293290
static Locale getLocale(BuildContext context) {

lib/state/authState.dart

+12-14
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class AuthState extends AppState {
7474

7575
/// Verify user's credentials for login
7676
Future<String?> signIn(String email, String password,
77-
{required GlobalKey<ScaffoldState> scaffoldKey}) async {
77+
{required BuildContext context}) async {
7878
try {
7979
isBusy = true;
8080
var result = await _firebaseAuth.signInWithEmailAndPassword(
@@ -84,17 +84,17 @@ class AuthState extends AppState {
8484
return user!.uid;
8585
} on FirebaseException catch (error) {
8686
if (error.code == 'firebase_auth/user-not-found') {
87-
Utility.customSnackBar(scaffoldKey, 'User not found');
87+
Utility.customSnackBar(context, 'User not found');
8888
} else {
8989
Utility.customSnackBar(
90-
scaffoldKey,
90+
context,
9191
error.message ?? 'Something went wrong',
9292
);
9393
}
9494
cprint(error, errorIn: 'signIn');
9595
return null;
9696
} catch (error) {
97-
Utility.customSnackBar(scaffoldKey, error.toString());
97+
Utility.customSnackBar(context, error.toString());
9898
cprint(error, errorIn: 'signIn');
9999

100100
return null;
@@ -173,8 +173,7 @@ class AuthState extends AppState {
173173

174174
/// Create new user's profile in db
175175
Future<String?> signUp(UserModel userModel,
176-
{required GlobalKey<ScaffoldState> scaffoldKey,
177-
required String password}) async {
176+
{required BuildContext context, required String password}) async {
178177
try {
179178
isBusy = true;
180179
var result = await _firebaseAuth.createUserWithEmailAndPassword(
@@ -197,7 +196,7 @@ class AuthState extends AppState {
197196
} catch (error) {
198197
isBusy = false;
199198
cprint(error, errorIn: 'signUp');
200-
Utility.customSnackBar(scaffoldKey, error.toString());
199+
Utility.customSnackBar(context, error.toString());
201200
return null;
202201
}
203202
}
@@ -260,22 +259,21 @@ class AuthState extends AppState {
260259
}
261260

262261
/// Send email verification link to email2
263-
Future<void> sendEmailVerification(
264-
GlobalKey<ScaffoldState> scaffoldKey) async {
262+
Future<void> sendEmailVerification(BuildContext context) async {
265263
User user = _firebaseAuth.currentUser!;
266264
user.sendEmailVerification().then((_) {
267265
Utility.logEvent('email_verification_sent',
268266
parameter: {userModel!.displayName!: user.email});
269267
Utility.customSnackBar(
270-
scaffoldKey,
268+
context,
271269
'An email verification link is send to your email.',
272270
);
273271
}).catchError((error) {
274272
cprint(error.message, errorIn: 'sendEmailVerification');
275273
Utility.logEvent('email_verification_block',
276274
parameter: {userModel!.displayName!: user.email});
277275
Utility.customSnackBar(
278-
scaffoldKey,
276+
context,
279277
error.message,
280278
);
281279
});
@@ -289,17 +287,17 @@ class AuthState extends AppState {
289287

290288
/// Send password reset link to email
291289
Future<void> forgetPassword(String email,
292-
{required GlobalKey<ScaffoldState> scaffoldKey}) async {
290+
{required BuildContext context}) async {
293291
try {
294292
await _firebaseAuth.sendPasswordResetEmail(email: email).then((value) {
295-
Utility.customSnackBar(scaffoldKey,
293+
Utility.customSnackBar(context,
296294
'A reset password link is sent yo your mail.You can reset your password from there');
297295
Utility.logEvent('forgot+password', parameter: {});
298296
}).catchError((error) {
299297
cprint(error.message);
300298
});
301299
} catch (error) {
302-
Utility.customSnackBar(scaffoldKey, error.toString());
300+
Utility.customSnackBar(context, error.toString());
303301
return Future.value(false);
304302
}
305303
}

lib/ui/page/Auth/forgetPasswordPage.dart

+5-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class ForgetPasswordPage extends StatefulWidget {
2020
class _ForgetPasswordPageState extends State<ForgetPasswordPage> {
2121
late FocusNode _focusNode;
2222
late TextEditingController _emailController;
23-
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
2423
@override
2524
void initState() {
2625
_focusNode = FocusNode();
@@ -48,14 +47,14 @@ class _ForgetPasswordPageState extends State<ForgetPasswordPage> {
4847
const SizedBox(
4948
height: 50,
5049
),
51-
_entryFeild('Enter email', controller: _emailController),
50+
_entryField('Enter email', controller: _emailController),
5251
// SizedBox(height: 10,),
5352
_submitButton(context),
5453
],
5554
));
5655
}
5756

58-
Widget _entryFeild(String hint,
57+
Widget _entryField(String hint,
5958
{required TextEditingController controller, bool isPassword = false}) {
6059
return Container(
6160
margin: const EdgeInsets.symmetric(vertical: 15),
@@ -116,26 +115,25 @@ class _ForgetPasswordPageState extends State<ForgetPasswordPage> {
116115

117116
void _submit() {
118117
if (_emailController.text.isEmpty) {
119-
Utility.customSnackBar(_scaffoldKey, 'Email field cannot be empty');
118+
Utility.customSnackBar(context, 'Email field cannot be empty');
120119
return;
121120
}
122121
var isValidEmail = Utility.validateEmail(
123122
_emailController.text,
124123
);
125124
if (!isValidEmail) {
126-
Utility.customSnackBar(_scaffoldKey, 'Please enter valid email address');
125+
Utility.customSnackBar(context, 'Please enter valid email address');
127126
return;
128127
}
129128

130129
_focusNode.unfocus();
131130
var state = Provider.of<AuthState>(context, listen: false);
132-
state.forgetPassword(_emailController.text, scaffoldKey: _scaffoldKey);
131+
state.forgetPassword(_emailController.text, context: context);
133132
}
134133

135134
@override
136135
Widget build(BuildContext context) {
137136
return Scaffold(
138-
key: _scaffoldKey,
139137
appBar: AppBar(
140138
title: customText('Forget Password',
141139
context: context, style: const TextStyle(fontSize: 20)),

lib/ui/page/Auth/signin.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class _SignInState extends State<SignIn> {
4545
crossAxisAlignment: CrossAxisAlignment.center,
4646
children: <Widget>[
4747
const SizedBox(height: 150),
48-
_entryFeild('Enter email', controller: _emailController),
49-
_entryFeild('Enter password',
48+
_entryField('Enter email', controller: _emailController),
49+
_entryField('Enter password',
5050
controller: _passwordController, isPassword: true),
5151
_emailLoginButton(context),
5252
const SizedBox(height: 20),
@@ -70,7 +70,7 @@ class _SignInState extends State<SignIn> {
7070
);
7171
}
7272

73-
Widget _entryFeild(String hint,
73+
Widget _entryField(String hint,
7474
{required TextEditingController controller, bool isPassword = false}) {
7575
return Container(
7676
margin: const EdgeInsets.symmetric(vertical: 15),
@@ -132,11 +132,11 @@ class _SignInState extends State<SignIn> {
132132
}
133133
loader.showLoader(context);
134134
var isValid = Utility.validateCredentials(
135-
_scaffoldKey, _emailController.text, _passwordController.text);
135+
context, _emailController.text, _passwordController.text);
136136
if (isValid) {
137137
state
138138
.signIn(_emailController.text, _passwordController.text,
139-
scaffoldKey: _scaffoldKey)
139+
context: context)
140140
.then((status) {
141141
if (state.user != null) {
142142
loader.hideLoader();

lib/ui/page/Auth/signup.dart

+12-16
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class _SignupState extends State<Signup> {
2828
late TextEditingController _confirmController;
2929
late CustomLoader loader;
3030
final _formKey = GlobalKey<FormState>();
31-
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
3231
@override
3332
void initState() {
3433
loader = CustomLoader();
@@ -58,13 +57,12 @@ class _SignupState extends State<Signup> {
5857
mainAxisAlignment: MainAxisAlignment.center,
5958
crossAxisAlignment: CrossAxisAlignment.center,
6059
children: <Widget>[
61-
_entryFeild('Name', controller: _nameController),
62-
_entryFeild('Enter email',
60+
_entryField('Name', controller: _nameController),
61+
_entryField('Enter email',
6362
controller: _emailController, isEmail: true),
64-
// _entryFeild('Mobile no',controller: _mobileController),
65-
_entryFeild('Enter password',
63+
_entryField('Enter password',
6664
controller: _passwordController, isPassword: true),
67-
_entryFeild('Confirm password',
65+
_entryField('Confirm password',
6866
controller: _confirmController, isPassword: true),
6967
_submitButton(context),
7068

@@ -82,7 +80,7 @@ class _SignupState extends State<Signup> {
8280
);
8381
}
8482

85-
Widget _entryFeild(String hint,
83+
Widget _entryField(String hint,
8684
{required TextEditingController controller,
8785
bool isPassword = false,
8886
bool isEmail = false}) {
@@ -121,28 +119,27 @@ class _SignupState extends State<Signup> {
121119
margin: const EdgeInsets.symmetric(vertical: 35),
122120
child: CustomFlatButton(
123121
label: "Sign up",
124-
onPressed: _submitForm,
122+
onPressed: () => _submitForm(context),
125123
borderRadius: 30,
126124
),
127125
);
128126
}
129127

130-
void _submitForm() {
128+
void _submitForm(BuildContext context) {
131129
if (_emailController.text.isEmpty) {
132-
Utility.customSnackBar(_scaffoldKey, 'Please enter name');
130+
Utility.customSnackBar(context, 'Please enter name');
133131
return;
134132
}
135133
if (_emailController.text.length > 27) {
136-
Utility.customSnackBar(
137-
_scaffoldKey, 'Name length cannot exceed 27 character');
134+
Utility.customSnackBar(context, 'Name length cannot exceed 27 character');
138135
return;
139136
}
140137
if (_emailController.text.isEmpty || _passwordController.text.isEmpty) {
141-
Utility.customSnackBar(_scaffoldKey, 'Please fill form carefully');
138+
Utility.customSnackBar(context, 'Please fill form carefully');
142139
return;
143140
} else if (_passwordController.text != _confirmController.text) {
144141
Utility.customSnackBar(
145-
_scaffoldKey, 'Password and confirm password did not match');
142+
context, 'Password and confirm password did not match');
146143
return;
147144
}
148145

@@ -166,7 +163,7 @@ class _SignupState extends State<Signup> {
166163
.signUp(
167164
user,
168165
password: _passwordController.text,
169-
scaffoldKey: _scaffoldKey,
166+
context: context,
170167
)
171168
.then((status) {
172169
print(status);
@@ -184,7 +181,6 @@ class _SignupState extends State<Signup> {
184181
@override
185182
Widget build(BuildContext context) {
186183
return Scaffold(
187-
key: _scaffoldKey,
188184
appBar: AppBar(
189185
title: customText(
190186
'Sign Up',

lib/ui/page/Auth/verifyEmail.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class _VerifyEmailPageState extends State<VerifyEmailPage> {
7474

7575
void _submit() {
7676
var state = Provider.of<AuthState>(context, listen: false);
77-
state.sendEmailVerification(_scaffoldKey);
77+
state.sendEmailVerification(context);
7878
}
7979

8080
@override

lib/ui/page/profile/EditProfilePage.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
197197

198198
void _submitButton() {
199199
if (_name.text.length > 27) {
200-
Utility.customSnackBar(
201-
_scaffoldKey, 'Name length cannot exceed 27 character');
200+
Utility.customSnackBar(context, 'Name length cannot exceed 27 character');
202201
return;
203202
}
204203
var state = Provider.of<AuthState>(context, listen: false);

lib/ui/page/profile/qrCode/scanner.dart

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'dart:io';
22
import 'dart:math';
3-
import 'dart:typed_data';
43
import 'dart:ui' as ui;
54

65
import 'package:flutter/material.dart';

lib/ui/theme/extention.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extension SizeHelper on BuildContext {
44
double get width => MediaQuery.of(this).size.width;
55
double get height => MediaQuery.of(this).size.height;
66

7-
double getDimention(context, double unit) {
7+
double getDimension(context, double unit) {
88
if (width <= 360.0) {
99
return unit / 1.3;
1010
} else {

0 commit comments

Comments
 (0)