Skip to content

Commit

Permalink
added snackbar-enhancement for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pr4nshul committed Nov 9, 2020
1 parent 8423ce3 commit e144913
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 64 deletions.
29 changes: 25 additions & 4 deletions lib/screens/authenticate/change_email.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ class _ChangeEmailState extends State<ChangeEmail> {
SizedBox(height: 20.0),
TextFormField(
initialValue: originalEmail,
decoration: InputDecoration(hintText: 'Email', enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: getBorderColorForInputFields(context), width: 2.0)), focusedBorder: OutlineInputBorder(borderSide: BorderSide(color: Theme.of(context).accentColor, width: 2.0))),
decoration: InputDecoration(
hintText: 'Email',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color:
getBorderColorForInputFields(context),
width: 2.0)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).accentColor,
width: 2.0))),
validator: (val) {
if (val.isEmpty) {
return 'Enter a valid Email';
Expand Down Expand Up @@ -80,7 +90,8 @@ class _ChangeEmailState extends State<ChangeEmail> {
});
await _auth.changeEmail(email);
await _auth.signOut();
await Navigator.pushNamedAndRemoveUntil(context, '/wrapper', (route) => false);
await Navigator.pushNamedAndRemoveUntil(
context, '/wrapper', (route) => false);
setState(() {
loading = false;
});
Expand All @@ -93,21 +104,31 @@ class _ChangeEmailState extends State<ChangeEmail> {
error = 'Your email is invalid';
break;
case 'ERROR_EMAIL_ALREADY_IN_USE':
error = 'Email is already in use on different account';
error =
'Email is already in use on different account';
break;
default:
error = 'An undefined Error happened.';
}
loading = false;
});
}
Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
duration: Duration(seconds: 2),
content: Text(
error,
style: TextStyle(color: Theme.of(context).accentColor),
),
));
}
}
}),
SizedBox(height: 24.0),
Text(
'Once you change your email, please log-in again by entering your new email ID and your previous password.',
style: TextStyle(fontSize: 17.0, fontStyle: FontStyle.italic),
style: TextStyle(
fontSize: 17.0, fontStyle: FontStyle.italic),
textAlign: TextAlign.justify,
),
SizedBox(
Expand Down
53 changes: 44 additions & 9 deletions lib/screens/authenticate/verified_email_check.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,22 @@ class _VerificationCheckState extends State<VerificationCheck> {
} catch (e) {
setState(() {
error = e.message;
Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
content: Text(
e.toString(),
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).accentColor),
)));
setState(() => loading = false);
});
}
},
label: Text(
'Logout',
style: TextStyle(color: getVisibleColorOnPrimaryColor(context)),
style: TextStyle(
color: getVisibleColorOnPrimaryColor(context)),
),
)
],
Expand All @@ -90,14 +99,21 @@ class _VerificationCheckState extends State<VerificationCheck> {
SizedBox(height: 20.0),
RichText(
text: TextSpan(
text: 'Verification email has been sent to your ID. Please click on the verification link in your mail.',
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold, color: getBorderColorForInputFields(context)),
text:
'Verification email has been sent to your ID. Please click on the verification link in your mail.',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: getBorderColorForInputFields(context)),
)),
SizedBox(height: 30.0),
RichText(
text: TextSpan(
text: 'The registered email id is: ${email}',
style: TextStyle(fontSize: 17.0, color: getBorderColorForInputFields(context), fontWeight: FontWeight.w700),
style: TextStyle(
fontSize: 17.0,
color: getBorderColorForInputFields(context),
fontWeight: FontWeight.w700),
),
),
SizedBox(
Expand All @@ -110,13 +126,24 @@ class _VerificationCheckState extends State<VerificationCheck> {
color: Theme.of(context).accentColor,
child: Text(
'Resend email',
style: TextStyle(color: getVisibleColorOnAccentColor(context)),
style: TextStyle(
color: getVisibleColorOnAccentColor(context)),
),
onPressed: () {
try {
_auth.verificationEmail(currentuser);
} catch (e) {
print(e.toString());
Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor:
Theme.of(context).primaryColor,
content: Text(
e.toString(),
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).accentColor,
),
)));
//need to show error in snackbar.
setState(() {
error = e.toString();
Expand All @@ -128,19 +155,27 @@ class _VerificationCheckState extends State<VerificationCheck> {
color: Theme.of(context).accentColor,
child: Text(
'Change email',
style: TextStyle(color: getVisibleColorOnAccentColor(context)),
style: TextStyle(
color: getVisibleColorOnAccentColor(context)),
),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => ChangeEmail()));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChangeEmail()));
},
),
],
),
SizedBox(height: 20.0),
RichText(
text: TextSpan(
text: 'You will be auto-redirected to dashboard once you verify your account.',
style: TextStyle(color: Colors.red, fontSize: 20.0, fontStyle: FontStyle.italic),
text:
'You will be auto-redirected to dashboard once you verify your account.',
style: TextStyle(
color: Colors.red,
fontSize: 20.0,
fontStyle: FontStyle.italic),
)),
SizedBox(height: 20.0),
],
Expand Down
8 changes: 8 additions & 0 deletions lib/screens/createtrip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ class _CreateTripState extends State<CreateTrip> {
// ));
} catch (e) {
print(e.toString());
_scaffoldKey.currentState.showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
duration: Duration(seconds: 2),
content: Text(
e.toString(),
style: TextStyle(color: Theme.of(context).accentColor),
),
));
//String errStr = e.message ?? e.toString();
//final snackBar = SnackBar(content: Text(errStr), duration: Duration(seconds: 3));
//_scaffoldKey.currentState.showSnackBar(snackBar);
Expand Down
24 changes: 24 additions & 0 deletions lib/screens/groupdetailscreen/groupdetails.dart
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ class _GroupDetailsState extends State<GroupDetails> with AutomaticKeepAliveClie
} catch (e) {
await pr.hide();
print(e.toString());
Scaffold.of(ctx).showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
duration: Duration(seconds: 2),
content: Text(
e.toString(),
style: TextStyle(color: Theme.of(context).accentColor),
),
));
}
},
),
Expand Down Expand Up @@ -376,6 +384,14 @@ class _GroupDetailsState extends State<GroupDetails> with AutomaticKeepAliveClie
} catch (e) {
await pr.hide();
print(e.toString());
Scaffold.of(ctx).showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
duration: Duration(seconds: 2),
content: Text(
e.toString(),
style: TextStyle(color: Theme.of(context).accentColor),
),
));
}
Navigator.of(context).pop();
// final snackBar = SnackBar(
Expand All @@ -402,6 +418,14 @@ class _GroupDetailsState extends State<GroupDetails> with AutomaticKeepAliveClie
}
} catch (e) {
print(e.toString());
Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
duration: Duration(seconds: 2),
content: Text(
e.toString(),
style: TextStyle(color: Theme.of(context).accentColor),
),
));
}
},
padding: EdgeInsets.all(20),
Expand Down
8 changes: 8 additions & 0 deletions lib/screens/groupscreen/editgroup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ class _EditGroupState extends State<EditGroup> {
await _databaseService.updateGroup(groupUID, _selectedStartDate, _selectedStartTime, _selectedEndDate, _selectedEndTime, privacy, _maxPoolers);
} catch (e) {
print(e.toString());
_scaffoldKey.currentState.showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
duration: Duration(seconds: 2),
content: Text(
e.toString(),
style: TextStyle(color: Theme.of(context).accentColor),
),
));
}
}

Expand Down
24 changes: 24 additions & 0 deletions lib/screens/groupscreen/group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ class _GroupPageState extends State<GroupPage> with AutomaticKeepAliveClientMixi
});
} catch (e) {
print(e.toString());
scaffoldKey.currentState.showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
duration: Duration(seconds: 2),
content: Text(
e.toString(),
style: TextStyle(color: Theme.of(context).accentColor),
),
));
}
},
label: Text('End Trip'),
Expand Down Expand Up @@ -203,6 +211,14 @@ class _GroupPageState extends State<GroupPage> with AutomaticKeepAliveClientMixi
});
} catch (e) {
print(e.toString());
scaffoldKey.currentState.showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
duration: Duration(seconds: 2),
content: Text(
e.toString(),
style: TextStyle(color: Theme.of(context).accentColor),
),
));
}
},
label: Text('Leave Group'),
Expand Down Expand Up @@ -494,6 +510,14 @@ class _GroupPageState extends State<GroupPage> with AutomaticKeepAliveClientMixi
} catch (e) {
await pr.hide();
print(e.toString());
Scaffold.of(context).showSnackBar(SnackBar(
backgroundColor: Theme.of(context).primaryColor,
duration: Duration(seconds: 2),
content: Text(
e.toString(),
style: TextStyle(color: Theme.of(context).accentColor),
),
));
}
},
),
Expand Down

0 comments on commit e144913

Please sign in to comment.