Add eror message on login screen
This commit is contained in:
parent
3ac7d94c03
commit
ef2174aaa9
1 changed files with 182 additions and 14 deletions
|
@ -2,7 +2,6 @@ import 'package:lottie/lottie.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:nekoya_flutter/api/api.dart';
|
import 'package:nekoya_flutter/api/api.dart';
|
||||||
import 'package:nekoya_flutter/components/login_error.dart';
|
|
||||||
import 'package:nekoya_flutter/components/menu.dart';
|
import 'package:nekoya_flutter/components/menu.dart';
|
||||||
import 'package:nekoya_flutter/data/auth.dart';
|
import 'package:nekoya_flutter/data/auth.dart';
|
||||||
import 'package:nekoya_flutter/utils/utils.dart';
|
import 'package:nekoya_flutter/utils/utils.dart';
|
||||||
|
@ -138,19 +137,28 @@ class LoginFormState extends State<LoginForm> {
|
||||||
backgroundColor: MaterialStateProperty.all(const Color(0xff8B0000)),
|
backgroundColor: MaterialStateProperty.all(const Color(0xff8B0000)),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
submitForm(context).then((res) {
|
if (emailController.text.isEmpty || passwordController.text.isEmpty) {
|
||||||
if (res['statusCode'] == 200) {
|
showAlertDialog(context);
|
||||||
addSession(res['data']['id'], res['data']['session_token']);
|
} else {
|
||||||
Navigator.pop(context);
|
submitForm(context).then((res) {
|
||||||
Navigator.pushReplacement(
|
if (res['statusCode'] == 200) {
|
||||||
context,
|
addSession(res['data']['id'], res['data']['session_token']);
|
||||||
MaterialPageRoute(
|
Navigator.pop(context);
|
||||||
builder: (context) => const Menu(initialScreen: 2)));
|
Navigator.pushReplacement(
|
||||||
} else {
|
context,
|
||||||
Navigator.push(context,
|
MaterialPageRoute(
|
||||||
MaterialPageRoute(builder: (context) => const LoginError()));
|
builder: (context) => const Menu(initialScreen: 2)));
|
||||||
}
|
} else if (res['statusCode'] == 204) {
|
||||||
});
|
showEmailNotRegister(context);
|
||||||
|
} else if (res['statusCode'] == 205) {
|
||||||
|
showEmailWarn(context);
|
||||||
|
} else if (res['statusCode'] == 400) {
|
||||||
|
showBad(context);
|
||||||
|
} else if (res['statusCode'] == 401) {
|
||||||
|
showUnautorized(context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'Login',
|
'Login',
|
||||||
|
@ -197,6 +205,166 @@ class LoginFormState extends State<LoginForm> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showAlertDialog(BuildContext context) {
|
||||||
|
Widget okButton = TextButton(
|
||||||
|
child: const Text("OK", style: TextStyle(color: Colors.red)),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context, rootNavigator: true).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
AlertDialog alert = AlertDialog(
|
||||||
|
backgroundColor: const Color(0xff1b1c1e),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
"Error",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
content: const Text(
|
||||||
|
"Enter Your Email Or Password",
|
||||||
|
style: TextStyle(color: Colors.white70),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
okButton,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return alert;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
showEmailNotRegister(BuildContext context) {
|
||||||
|
Widget okButton = TextButton(
|
||||||
|
child: const Text("OK", style: TextStyle(color: Colors.red)),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context, rootNavigator: true).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
AlertDialog alert = AlertDialog(
|
||||||
|
backgroundColor: const Color(0xff1b1c1e),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
"Error",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
content: const Text(
|
||||||
|
"Sorry your email not registered yet",
|
||||||
|
style: TextStyle(color: Colors.white70),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
okButton,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return alert;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
showEmailWarn(BuildContext context) {
|
||||||
|
Widget okButton = TextButton(
|
||||||
|
child: const Text("OK", style: TextStyle(color: Colors.red)),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context, rootNavigator: true).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
AlertDialog alert = AlertDialog(
|
||||||
|
backgroundColor: const Color(0xff1b1c1e),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
"Error",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
content: const Text(
|
||||||
|
"Sorry Then Email Or Password You Entered Is Wrong",
|
||||||
|
style: TextStyle(color: Colors.white70),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
okButton,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return alert;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
showBad(BuildContext context) {
|
||||||
|
Widget okButton = TextButton(
|
||||||
|
child: const Text("OK", style: TextStyle(color: Colors.red)),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context, rootNavigator: true).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
AlertDialog alert = AlertDialog(
|
||||||
|
backgroundColor: const Color(0xff1b1c1e),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
"Error",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
content: const Text(
|
||||||
|
"Bad Connection",
|
||||||
|
style: TextStyle(color: Colors.white70),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
okButton,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return alert;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
showUnautorized(BuildContext context) {
|
||||||
|
Widget okButton = TextButton(
|
||||||
|
child: const Text("OK", style: TextStyle(color: Colors.red)),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context, rootNavigator: true).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
AlertDialog alert = AlertDialog(
|
||||||
|
backgroundColor: const Color(0xff1b1c1e),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
title: const Text(
|
||||||
|
"Error",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
content: const Text(
|
||||||
|
"Blalaala",
|
||||||
|
style: TextStyle(color: Colors.white70),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
okButton,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return alert;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
|
|
Loading…
Add table
Reference in a new issue