update
This commit is contained in:
parent
e3dc94a768
commit
08de65a681
8 changed files with 251 additions and 68 deletions
|
|
@ -1,15 +1,136 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
||||
import 'package:pharmacy_mobile/auth/auth_service.dart';
|
||||
import 'package:pharmacy_mobile/blocs/guest/functions/bloc_getgueststatus.dart';
|
||||
import 'package:pharmacy_mobile/blocs/guest/functions/bloc_setguestoff.dart';
|
||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/customer_pagebackground_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/customer_title_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/glossy_container_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/input_form_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/snackbar_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
import 'package:animated_notch_bottom_bar/animated_notch_bottom_bar/animated_notch_bottom_bar.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
class CustomerCartPage extends StatelessWidget {
|
||||
class CustomerCartPage extends StatefulWidget {
|
||||
final NotchBottomBarController? controller;
|
||||
const CustomerCartPage({super.key, this.controller});
|
||||
|
||||
@override
|
||||
State<CustomerCartPage> createState() => _CustomerCartPageState();
|
||||
}
|
||||
|
||||
class _CustomerCartPageState extends State<CustomerCartPage> {
|
||||
final _emailController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
final _authService = AuthService();
|
||||
final _focusNode = FocusNode();
|
||||
bool _isLoading = false;
|
||||
double containerHeight = 0.35;
|
||||
late bool _isGuest = false;
|
||||
|
||||
void checkGuest() async {
|
||||
final isGuest = await blocGetGuestStatus(context);
|
||||
|
||||
setState(() {
|
||||
_isGuest = isGuest;
|
||||
});
|
||||
}
|
||||
|
||||
void _signIn() async {
|
||||
final email = _emailController.text;
|
||||
final password = _passwordController.text;
|
||||
|
||||
if (email.isEmpty) {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: Please enter a valid email', false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.isEmpty) {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: Please enter a password', false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
containerHeight = 0.365;
|
||||
});
|
||||
|
||||
try {
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
await _authService.signIn(email, password);
|
||||
|
||||
final user = _authService.getCurrentUser();
|
||||
|
||||
if (user != null) {
|
||||
// ignore: use_build_context_synchronously
|
||||
final disableGuest = await blocSetGuestOff(context);
|
||||
|
||||
if (disableGuest) {
|
||||
// ignore: use_build_context_synchronously
|
||||
showNotification(context, 'Login Successful', true);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (user.contains('admin')) {
|
||||
if (mounted) context.push('/main');
|
||||
} else {
|
||||
if (mounted) context.push('/customer');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// ignore: use_build_context_synchronously
|
||||
showNotification(context, 'Error: Login failed', false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (e is AuthException) {
|
||||
final errorMessage = e.message;
|
||||
|
||||
if (mounted) {
|
||||
if (errorMessage == 'Invalid login credentials') {
|
||||
showNotification(context, 'Error: Invalid Email or Password', false);
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
containerHeight = 0.35;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void autoRun() async {
|
||||
checkGuest();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
autoRun();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailController.dispose();
|
||||
_passwordController.dispose();
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
|
@ -19,18 +140,76 @@ class CustomerCartPage extends StatelessWidget {
|
|||
const Gap(68),
|
||||
const CustomerTitleWidget(),
|
||||
const Gap(32),
|
||||
if (_isGuest)
|
||||
SizedBox(
|
||||
child: Column(
|
||||
children: [
|
||||
FaIcon(
|
||||
FontAwesomeIcons.cartShopping,
|
||||
size: 56,
|
||||
color: const Color.fromRGBO(255, 255, 255, 1),
|
||||
),
|
||||
const Gap(16),
|
||||
const TextWidget(
|
||||
text: 'Cart is disabled for guests',
|
||||
size: 16,
|
||||
),
|
||||
const Gap(8),
|
||||
const TextWidget(
|
||||
text: 'Please login',
|
||||
size: 32,
|
||||
),
|
||||
const Gap(8),
|
||||
const TextWidget(
|
||||
text: 'to use your cart',
|
||||
size: 24,
|
||||
),
|
||||
const Gap(32),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 32, right: 32),
|
||||
child: GlossyContainerWidget(
|
||||
child: Form(
|
||||
child: Column(
|
||||
children: [
|
||||
InputFormWidget(label: 'Email', controller: _emailController),
|
||||
const Gap(16),
|
||||
InputFormWidget(
|
||||
label: 'Password',
|
||||
controller: _passwordController,
|
||||
password: true,
|
||||
onSubmitted: (String password) {
|
||||
_signIn();
|
||||
},
|
||||
),
|
||||
const Gap(40),
|
||||
ButtonWithProgressWidget(
|
||||
trigger: _isLoading, progressText: 'Logging In', buttonText: 'Login', onPressed: _signIn),
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox(
|
||||
child: Column(
|
||||
children: [
|
||||
FaIcon(
|
||||
FontAwesomeIcons.cartShopping,
|
||||
size: 56,
|
||||
color: const Color.fromRGBO(255, 255, 255, 1),
|
||||
),
|
||||
const Gap(16),
|
||||
const TextWidget(
|
||||
text: 'No items in cart',
|
||||
size: 24,
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
// const TextWidget(text: 'My Cart'),
|
||||
// const Gap(16),
|
||||
FaIcon(
|
||||
FontAwesomeIcons.cartShopping,
|
||||
size: 56,
|
||||
color: const Color.fromRGBO(255, 255, 255, 1),
|
||||
),
|
||||
const Gap(16),
|
||||
const TextWidget(
|
||||
text: 'No items in cart',
|
||||
size: 24,
|
||||
)
|
||||
],
|
||||
)));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue