This commit is contained in:
Patrick Alvin Alcala 2025-02-17 17:08:14 +08:00
parent 71a289b74c
commit d4706f5f2e
13 changed files with 86 additions and 10 deletions

View file

@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:pharmacy_mobile/auth/auth_service.dart';
import 'package:pharmacy_mobile/pages/customer_page.dart';
import 'package:pharmacy_mobile/pages/index_page.dart';
import 'package:pharmacy_mobile/pages/main_page.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
@ -8,6 +10,8 @@ class AuthGate extends StatelessWidget {
@override
Widget build(BuildContext context) {
final authService = AuthService();
return StreamBuilder(
stream: Supabase.instance.client.auth.onAuthStateChange,
builder: (context, snapshot) {
@ -24,7 +28,13 @@ class AuthGate extends StatelessWidget {
final session = snapshot.hasData ? snapshot.data!.session : null;
if (session != null) {
return const MainPage();
final user = authService.getCurrentUser();
if (user != null && user.contains('admin')) {
return const MainPage();
} else {
return const CustomerPage();
}
} else {
return const IndexPage();
}

View file

@ -1,12 +1,12 @@
import 'package:flutter/material.dart';
import 'package:pharmacy_mobile/auth/auth_gate.dart';
import 'package:pharmacy_mobile/pages/add_category.dart';
import 'package:pharmacy_mobile/pages/add_generics.dart';
import 'package:pharmacy_mobile/pages/add_medicine.dart';
import 'package:pharmacy_mobile/pages/add_stock.dart';
import 'package:pharmacy_mobile/pages/add_type.dart';
import 'package:pharmacy_mobile/pages/add_category_page.dart';
import 'package:pharmacy_mobile/pages/add_generics_page.dart';
import 'package:pharmacy_mobile/pages/add_medicine_page.dart';
import 'package:pharmacy_mobile/pages/add_stock_page.dart';
import 'package:pharmacy_mobile/pages/add_type_page.dart';
import 'package:pharmacy_mobile/pages/customer_page.dart';
import 'package:pharmacy_mobile/pages/delete_stock.dart';
import 'package:pharmacy_mobile/pages/delete_stock_page.dart';
import 'package:pharmacy_mobile/pages/list_stocks.dart';
import 'package:pharmacy_mobile/pages/login_page.dart';
import 'package:go_router/go_router.dart';

View file

@ -1,20 +1,42 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:gap/gap.dart';
import 'package:pharmacy_mobile/auth/auth_service.dart';
import 'package:pharmacy_mobile/widgets/button_widget.dart';
import 'package:pharmacy_mobile/widgets/menu_widget.dart';
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
import 'package:pharmacy_mobile/widgets/snackbar_widget.dart';
import 'package:pharmacy_mobile/widgets/text_widget.dart';
import 'package:pharmacy_mobile/widgets/title_widget.dart';
import 'package:go_router/go_router.dart';
class CustomerPage extends StatelessWidget {
class CustomerPage extends StatefulWidget {
const CustomerPage({super.key});
@override
State<CustomerPage> createState() => _CustomerPageState();
}
class _CustomerPageState extends State<CustomerPage> {
final _authService = AuthService();
void sample() {}
void signOut() async {
// ignore: use_build_context_synchronously
await _authService.signOut().then((_) => {context.go('/'), showNotification(context, 'Logged Out', true)});
}
@override
Widget build(BuildContext context) {
return PopScope(
canPop: false,
child: Scaffold(
resizeToAvoidBottomInset: false,
body: SingleChildScrollView(
child: PageBackgroundWidget(
height: MediaQuery.of(context).size.height + 400,
page: 'menu',
child: Center(
child: Column(
children: [
@ -23,6 +45,16 @@ class CustomerPage extends StatelessWidget {
const Gap(32),
const TextWidget(text: 'Menu'),
const Gap(16),
const MenuWidget(icon: FontAwesomeIcons.kitMedical, text: 'Buy Medicine', color: 'blue'),
const Gap(32),
ButtonWidget(
text: 'Logout',
onPressed: signOut,
)
// CustomerMenuWidget(
// onHomePressed: sample,
// onProfilePressed: sample,
// )
],
))),
),

View file

@ -26,7 +26,7 @@ class ButtonWidget extends StatelessWidget {
: ElevatedButton.styleFrom(
foregroundColor: const Color.fromRGBO(0, 0, 0, 1), // text color
backgroundColor: const Color.fromRGBO(198, 133, 232, 1), // background color
side: const BorderSide(color: Color.fromRGBO(79, 51, 94, 1)), // border color
side: const BorderSide(color: Color.fromRGBO(79, 51, 94, 0.4)), // border color
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20), // rounded corners
),

View file

@ -0,0 +1,34 @@
import 'package:flutter/material.dart';
class CustomerMenuWidget extends StatelessWidget {
final VoidCallback? onHomePressed;
final VoidCallback? onProfilePressed;
const CustomerMenuWidget({super.key, this.onHomePressed, this.onProfilePressed});
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
GestureDetector(
onTap: onHomePressed,
child: Container(
color: Colors.white,
alignment: Alignment.center,
padding: EdgeInsets.all(24),
child: Text('Home', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
),
),
GestureDetector(
onTap: onProfilePressed,
child: Container(
color: Colors.white,
alignment: Alignment.center,
padding: EdgeInsets.all(24),
child: Text('Profile', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
),
),
],
);
}
}

View file

@ -24,7 +24,7 @@ class MenuWidget extends StatelessWidget {
width: MediaQuery.of(context).size.width - 96,
padding: const EdgeInsets.only(top: 16, bottom: 16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: color != null ? _getColorBasedOnString(color ?? '') : const Color.fromRGBO(255, 255, 255, 0.6),
width: 2),