update
This commit is contained in:
parent
a76d3a0f35
commit
e3dc94a768
33 changed files with 368 additions and 184 deletions
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:gap/gap.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:pharmacy_mobile/auth/auth_service.dart';
|
||||
import 'package:pharmacy_mobile/blocs/guest/functions/bloc_getgueststatus.dart';
|
||||
import 'package:pharmacy_mobile/widgets/button_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/customer_pagebackground_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/customer_title_widget.dart';
|
||||
|
|
@ -16,11 +17,25 @@ class CustomerProfilePage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _CustomerProfilePageState extends State<CustomerProfilePage> {
|
||||
final authService = AuthService();
|
||||
final _authService = AuthService();
|
||||
late bool _isGuest = false;
|
||||
|
||||
void _signOut() async {
|
||||
// ignore: use_build_context_synchronously
|
||||
await authService.signOut().then((_) => {context.go('/'), showNotification(context, 'Logged Out', true)});
|
||||
await _authService.signOut().then((_) => {context.go('/'), showNotification(context, 'Logged Out', true)});
|
||||
}
|
||||
|
||||
void checkGuest() async {
|
||||
final guest = await blocGetGuestStatus(context);
|
||||
setState(() {
|
||||
_isGuest = guest;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
checkGuest();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -34,7 +49,7 @@ class _CustomerProfilePageState extends State<CustomerProfilePage> {
|
|||
const Gap(68),
|
||||
const CustomerTitleWidget(),
|
||||
const Gap(32),
|
||||
const TextWidget(text: 'My Profile'),
|
||||
_isGuest ? const TextWidget(text: 'Guest Profile') : const TextWidget(text: 'My Profile'),
|
||||
const Gap(16),
|
||||
const Gap(32),
|
||||
ButtonWidget(text: 'Log Out', onPressed: _signOut)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,13 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:pharmacy_mobile/auth/auth_service.dart';
|
||||
import 'package:pharmacy_mobile/blocs/user/functions/bloc_getuser.dart';
|
||||
import 'package:pharmacy_mobile/blocs/user/functions/bloc_setuser.dart';
|
||||
import 'package:pharmacy_mobile/blocs/user/user_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/user/user_event.dart';
|
||||
import 'package:pharmacy_mobile/tables/cart.dart';
|
||||
import 'package:pharmacy_mobile/tables/stocks.dart';
|
||||
import 'package:pharmacy_mobile/tables/storage.dart';
|
||||
|
|
@ -43,16 +48,14 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
_stockList = await _stocks.getList();
|
||||
}
|
||||
|
||||
Future<String> _getCurrentUser() async {
|
||||
final result = _authService.getCurrentUser();
|
||||
Future<String> _getCurrentUserId() async {
|
||||
final result = _authService.getCurrentUserId();
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
Future<void> _getCarts() async {
|
||||
final currentUser = await _getCurrentUser();
|
||||
log('currentUser: $currentUser');
|
||||
final currentUser = await _getCurrentUserId();
|
||||
_cartList = await _carts.getCart(currentUser);
|
||||
log('cart: ${_cartList.toString()}');
|
||||
}
|
||||
|
||||
// Future<void> _getAllMedicines() async {
|
||||
|
|
@ -82,7 +85,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
void autoRun() async {
|
||||
await _getAllStocks();
|
||||
await _getCarts();
|
||||
// await _getAllMedicines();
|
||||
// // // await _getAllMedicines();
|
||||
await _getURL();
|
||||
}
|
||||
|
||||
|
|
@ -125,31 +128,6 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
|
|||
),
|
||||
),
|
||||
const Gap(32),
|
||||
// Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.end,
|
||||
// children: [
|
||||
// ToggleSwitch(
|
||||
// fontSize: 12,
|
||||
// minWidth: 64,
|
||||
// minHeight: 32,
|
||||
// initialLabelIndex: 1,
|
||||
// cornerRadius: 20,
|
||||
// activeFgColor: Colors.white,
|
||||
// inactiveBgColor: const Color.fromRGBO(81, 81, 81, 1),
|
||||
// inactiveFgColor: const Color.fromRGBO(177, 175, 175, 1),
|
||||
// totalSwitches: 2,
|
||||
// labels: ['All', 'Stocks'],
|
||||
// activeBgColors: [
|
||||
// [const Color.fromRGBO(40, 112, 143, 1)],
|
||||
// [const Color.fromRGBO(40, 112, 143, 1)],
|
||||
// ],
|
||||
// // onToggle: (index) {
|
||||
// // print('switched to: $index');
|
||||
// // },
|
||||
// ),
|
||||
// const Gap(8)
|
||||
// ],
|
||||
// ),
|
||||
const IndicatorWidget(text: 'All Stocks'),
|
||||
const Gap(8),
|
||||
SingleChildScrollView(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:pharmacy_mobile/blocs/guest/functions/bloc_setgueston.dart';
|
||||
import 'package:pharmacy_mobile/blocs/guest/guest_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/guest/guest_event.dart';
|
||||
import 'package:pharmacy_mobile/widgets/button_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/image_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
||||
|
|
@ -21,6 +25,14 @@ class IndexPage extends StatelessWidget {
|
|||
context.push('/register');
|
||||
}
|
||||
|
||||
void loginAsGuest() async {
|
||||
final setGuest = await blocSetGuestOn(context);
|
||||
if (setGuest) {
|
||||
// ignore: use_build_context_synchronously
|
||||
context.push('/customer');
|
||||
}
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: PageBackgroundWidget(
|
||||
|
|
@ -41,6 +53,16 @@ class IndexPage extends StatelessWidget {
|
|||
ButtonWidget(text: 'Login', onPressed: gotoLogin),
|
||||
const Gap(8),
|
||||
ButtonWidget(text: 'Register', onPressed: gotoRegister, outline: true),
|
||||
const Gap(16),
|
||||
GestureDetector(
|
||||
onTap: loginAsGuest,
|
||||
child: const TextWidget(
|
||||
text: "Login as Guest",
|
||||
size: 12,
|
||||
underlined: true,
|
||||
color: Color.fromRGBO(198, 133, 232, 1),
|
||||
),
|
||||
),
|
||||
const Gap(32),
|
||||
const SloganWidget(),
|
||||
const Gap(32),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
|||
import 'package:go_router/go_router.dart';
|
||||
import 'package:gap/gap.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/glossy_container_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/input_form_widget.dart';
|
||||
|
|
@ -55,10 +57,14 @@ class _LoginPageState extends State<LoginPage> {
|
|||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
await _authService.signIn(email, password);
|
||||
|
||||
if (mounted) {
|
||||
final user = _authService.getCurrentUser();
|
||||
final user = _authService.getCurrentUser();
|
||||
|
||||
if (user != null) {
|
||||
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((_) {
|
||||
|
|
@ -68,6 +74,9 @@ class _LoginPageState extends State<LoginPage> {
|
|||
if (mounted) context.push('/customer');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// ignore: use_build_context_synchronously
|
||||
showNotification(context, 'Error: Login failed', false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
||||
import 'package:pharmacy_mobile/auth/auth_service.dart';
|
||||
import 'package:pharmacy_mobile/blocs/guest/guest_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/guest/guest_event.dart';
|
||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/glossy_container_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/input_form_widget.dart';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue