Skip to content

Commit

Permalink
Fix login caching issues
Browse files Browse the repository at this point in the history
  • Loading branch information
harveyjavier committed Nov 4, 2019
1 parent 28f1a11 commit a0da75e
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/screens/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class _LoginState extends State<Login> {

String _email_or_number, _password;
Map _user_data;
bool _obscureP = true, _signing_in = false, _account_matched = false;
bool _loading = true, _obscureP = true, _signing_in = false, _account_matched = false;

@override
initState() {
Expand All @@ -30,16 +30,23 @@ class _LoginState extends State<Login> {
}

void onMount() {
if (storage.getItem("registered") != null) {
_scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text("You have successfully signed up! User ID: " + storage.getItem("registered")["user_id"]),
duration: Duration(seconds: 2),
backgroundColor: Colors.green,
)
);
storage.clear();
}
storage.ready.then((_) {
print(storage.getItem("user_data"));
if (storage.getItem("user_data") == null)
{ setState(() { _loading = false; }); }
if (storage.getItem("user_data") != null)
{ Navigator.pushReplacement(context, MaterialPageRoute(builder: (BuildContext context) => NewsFeed())); }
if (storage.getItem("registered") != null) {
_scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Text("You have successfully signed up! User ID: " + storage.getItem("registered")["user_id"]),
duration: Duration(seconds: 2),
backgroundColor: Colors.green,
)
);
storage.clear();
}
});
}

Future<bool> _onBack() {
Expand Down Expand Up @@ -82,7 +89,7 @@ class _LoginState extends State<Login> {
loginBody() => SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[loginHeader(), loginFields()],
children: _loading ? <Widget>[loginLoader()] : <Widget>[loginHeader(), loginFields()],
),
);

Expand Down

0 comments on commit a0da75e

Please sign in to comment.