update
This commit is contained in:
parent
97e2291159
commit
57b8bdc067
17 changed files with 245 additions and 114 deletions
|
|
@ -9,6 +9,7 @@ import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
|||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/title_widget.dart';
|
||||
import 'package:quickalert/quickalert.dart';
|
||||
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
|
@ -23,31 +24,55 @@ class _LoginPageState extends State<LoginPage> {
|
|||
final _passwordController = TextEditingController();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
|
||||
bool _isLoading = false;
|
||||
|
||||
void _signIn() async {
|
||||
if (_isLoading) return;
|
||||
|
||||
final email = _emailController.text;
|
||||
final password = _passwordController.text;
|
||||
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
await _authService.signIn(email, password);
|
||||
// QuickAlert.show(
|
||||
// context: context,
|
||||
// type: QuickAlertType.success,
|
||||
// text: 'Login Successful',
|
||||
// autoCloseDuration: const Duration(seconds: 1),
|
||||
// showConfirmBtn: false,
|
||||
// );
|
||||
context.push('/main');
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
await _authService.signIn(email, password);
|
||||
if (mounted) {
|
||||
QuickAlert.show(
|
||||
context: context,
|
||||
type: QuickAlertType.success,
|
||||
text: 'Login Successful',
|
||||
autoCloseDuration: const Duration(seconds: 2),
|
||||
showConfirmBtn: false,
|
||||
).then((value) => {
|
||||
if (mounted && context.mounted) {context.push('/main')}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
QuickAlert.show(
|
||||
context: context,
|
||||
type: QuickAlertType.error,
|
||||
text: 'No Internet Connection',
|
||||
autoCloseDuration: const Duration(seconds: 2),
|
||||
showConfirmBtn: false,
|
||||
);
|
||||
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Error: $e')));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
QuickAlert.show(
|
||||
context: context,
|
||||
type: QuickAlertType.error,
|
||||
text: 'Error: $e',
|
||||
autoCloseDuration: const Duration(seconds: 2),
|
||||
autoCloseDuration: const Duration(seconds: 5),
|
||||
showConfirmBtn: false,
|
||||
);
|
||||
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Error: $e')));
|
||||
}
|
||||
} finally {
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
|
||||
// if (mounted) {
|
||||
|
|
@ -68,50 +93,61 @@ class _LoginPageState extends State<LoginPage> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: PageBackgroundWidget(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Gap(120),
|
||||
const TitleWidget(firstTextSize: 16, secondTextSize: 32),
|
||||
const Gap(32),
|
||||
const TextWidget(text: 'Login'),
|
||||
const Gap(16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.white), borderRadius: BorderRadius.all(Radius.circular(16))),
|
||||
child: Form(
|
||||
child: Column(
|
||||
children: [
|
||||
InputWidget(label: 'Email', controller: _emailController),
|
||||
const Gap(16),
|
||||
KeyboardListener(
|
||||
focusNode: _focusNode,
|
||||
onKeyEvent: (event) {
|
||||
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.enter) {
|
||||
_signIn();
|
||||
}
|
||||
},
|
||||
child: InputWidget(
|
||||
label: 'Password',
|
||||
controller: _passwordController,
|
||||
password: true,
|
||||
),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Gap(104),
|
||||
const TitleWidget(firstTextSize: 16, secondTextSize: 32),
|
||||
const Gap(32),
|
||||
const TextWidget(text: 'Login'),
|
||||
const Gap(16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(32),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color.fromARGB(219, 38, 17, 46),
|
||||
borderRadius: BorderRadius.all(Radius.circular(16)),
|
||||
// boxShadow: [
|
||||
// BoxShadow(
|
||||
// color: const Color.fromRGBO(0, 0, 0, 1).withOpacity(0.4), // Subtle shadow to give depth
|
||||
// spreadRadius: 0,
|
||||
// blurRadius: 4,
|
||||
// offset: Offset(0, 2),
|
||||
// )
|
||||
// ]
|
||||
),
|
||||
const Gap(24),
|
||||
// TextButton(onPressed: () => {_signIn()}, child: const Text('Login'))
|
||||
ButtonWidget(text: 'Login', onPressed: _signIn)
|
||||
],
|
||||
)),
|
||||
),
|
||||
child: Form(
|
||||
child: Column(
|
||||
children: [
|
||||
InputWidget(label: 'Email', controller: _emailController),
|
||||
const Gap(16),
|
||||
KeyboardListener(
|
||||
focusNode: _focusNode,
|
||||
onKeyEvent: (event) {
|
||||
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.enter) {
|
||||
_signIn();
|
||||
}
|
||||
},
|
||||
child: InputWidget(
|
||||
label: 'Password',
|
||||
controller: _passwordController,
|
||||
password: true,
|
||||
),
|
||||
),
|
||||
const Gap(24),
|
||||
// TextButton(onPressed: () => {_signIn()}, child: const Text('Login'))
|
||||
ButtonWidget(text: 'Login', onPressed: _signIn)
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue