update
This commit is contained in:
parent
b2aeb642cc
commit
b6b7ab6e84
8 changed files with 155 additions and 61 deletions
|
|
@ -14,7 +14,9 @@ class AuthGate extends StatelessWidget {
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Center(
|
body: Center(
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(
|
||||||
|
color: Colors.green,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:pharmacy_mobile/pages/index_page.dart';
|
import 'package:pharmacy_mobile/auth/auth_gate.dart';
|
||||||
|
// import 'package:pharmacy_mobile/pages/index_page.dart';
|
||||||
import 'package:pharmacy_mobile/pages/login_page.dart';
|
import 'package:pharmacy_mobile/pages/login_page.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
import 'package:pharmacy_mobile/pages/main_page.dart';
|
||||||
import 'package:pharmacy_mobile/pages/register_page.dart';
|
import 'package:pharmacy_mobile/pages/register_page.dart';
|
||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
|
|
||||||
|
|
@ -32,7 +34,7 @@ final _router = GoRouter(
|
||||||
GoRoute(
|
GoRoute(
|
||||||
name: 'index', // Optional, add name to your routes. Allows you navigate by name instead of path
|
name: 'index', // Optional, add name to your routes. Allows you navigate by name instead of path
|
||||||
path: '/',
|
path: '/',
|
||||||
builder: (context, state) => IndexPage(),
|
builder: (context, state) => AuthGate(),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
name: 'login',
|
name: 'login',
|
||||||
|
|
@ -44,6 +46,11 @@ final _router = GoRouter(
|
||||||
path: '/register',
|
path: '/register',
|
||||||
builder: (context, state) => RegisterPage(),
|
builder: (context, state) => RegisterPage(),
|
||||||
),
|
),
|
||||||
|
GoRoute(
|
||||||
|
name: 'main',
|
||||||
|
path: '/main',
|
||||||
|
builder: (context, state) => MainPage(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class IndexPage extends StatelessWidget {
|
||||||
width: 256, cacheWidth: (256 * MediaQuery.of(context).devicePixelRatio).round()),
|
width: 256, cacheWidth: (256 * MediaQuery.of(context).devicePixelRatio).round()),
|
||||||
),
|
),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
TextButton(onPressed: () => {context.push('/login')}, child: Text('data'))
|
TextButton(onPressed: () => {context.push('/login')}, child: const Text('Login'))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:pharmacy_mobile/auth/auth_service.dart';
|
import 'package:pharmacy_mobile/auth/auth_service.dart';
|
||||||
import 'package:pharmacy_mobile/main.dart';
|
import 'package:pharmacy_mobile/main.dart';
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
import 'package:quickalert/quickalert.dart';
|
||||||
|
|
||||||
class LoginPage extends StatefulWidget {
|
class LoginPage extends StatefulWidget {
|
||||||
const LoginPage({super.key});
|
const LoginPage({super.key});
|
||||||
|
|
@ -17,16 +19,30 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
final _emailController = TextEditingController();
|
final _emailController = TextEditingController();
|
||||||
final _passwordController = TextEditingController();
|
final _passwordController = TextEditingController();
|
||||||
|
|
||||||
Future<void> _signIn() async {
|
void _signIn() async {
|
||||||
final email = _emailController.text;
|
final email = _emailController.text;
|
||||||
final password = _passwordController.text;
|
final password = _passwordController.text;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await _authService.signIn(email, password);
|
await _authService.signIn(email, password);
|
||||||
log('message');
|
// QuickAlert.show(
|
||||||
|
// context: context,
|
||||||
|
// type: QuickAlertType.success,
|
||||||
|
// text: 'Login Successful',
|
||||||
|
// autoCloseDuration: const Duration(seconds: 1),
|
||||||
|
// showConfirmBtn: false,
|
||||||
|
// );
|
||||||
|
context.push('/main');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Error: $e')));
|
QuickAlert.show(
|
||||||
|
context: context,
|
||||||
|
type: QuickAlertType.error,
|
||||||
|
text: 'Error: $e',
|
||||||
|
autoCloseDuration: const Duration(seconds: 2),
|
||||||
|
showConfirmBtn: false,
|
||||||
|
);
|
||||||
|
// ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Error: $e')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,76 +103,28 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
children: [
|
children: [
|
||||||
TextFormField(
|
TextFormField(
|
||||||
controller: _emailController,
|
controller: _emailController,
|
||||||
decoration: InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Email',
|
labelText: 'Email',
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
style: TextStyle(color: Colors.white),
|
style: const TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
const Gap(8),
|
const Gap(8),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
|
obscureText: true,
|
||||||
controller: _passwordController,
|
controller: _passwordController,
|
||||||
decoration: InputDecoration(
|
decoration: const InputDecoration(
|
||||||
labelText: 'Password',
|
labelText: 'Password',
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
style: TextStyle(color: Colors.white),
|
style: const TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
TextButton(onPressed: () => {_signIn()}, child: Text('Login'))
|
TextButton(onPressed: () => {_signIn()}, child: const Text('Login'))
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Form(
|
|
||||||
|
|
||||||
// child: Column(
|
|
||||||
// children: [
|
|
||||||
// TextFormField(
|
|
||||||
// decoration: InputDecoration(
|
|
||||||
// labelText: 'Email',
|
|
||||||
// border: OutlineInputBorder(),
|
|
||||||
// ),
|
|
||||||
// validator: (value) {
|
|
||||||
// if (value.isEmpty) {
|
|
||||||
// return 'Please enter an email';
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// },
|
|
||||||
// onSaved: (value) => _email = value,
|
|
||||||
// ),
|
|
||||||
// SizedBox(height: 20),
|
|
||||||
// TextFormField(
|
|
||||||
// decoration: InputDecoration(
|
|
||||||
// labelText: 'Password',
|
|
||||||
// border: OutlineInputBorder(),
|
|
||||||
// ),
|
|
||||||
// obscureText: true,
|
|
||||||
// validator: (value) {
|
|
||||||
// if (value.isEmpty) {
|
|
||||||
// return 'Please enter a password';
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// },
|
|
||||||
// onSaved: (value) => _password = value,
|
|
||||||
// ),
|
|
||||||
// SizedBox(height: 20),
|
|
||||||
// ElevatedButton(
|
|
||||||
// onPressed: () {
|
|
||||||
// if (_formKey.currentState.validate()) {
|
|
||||||
// _formKey.currentState.save();
|
|
||||||
// // Login logic here
|
|
||||||
// print('Email: $_email, Password: $_password');
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// child: Text('Login'),
|
|
||||||
// ),
|
|
||||||
// ],
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
66
lib/pages/main_page.dart
Normal file
66
lib/pages/main_page.dart
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
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:google_fonts/google_fonts.dart';
|
||||||
|
import 'package:pharmacy_mobile/auth/auth_service.dart';
|
||||||
|
import 'package:pharmacy_mobile/widgets/menu_widget.dart';
|
||||||
|
|
||||||
|
class MainPage extends StatelessWidget {
|
||||||
|
const MainPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final authService = AuthService();
|
||||||
|
|
||||||
|
void signOut() async {
|
||||||
|
await authService.signOut();
|
||||||
|
context.push('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
body: Container(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
height: MediaQuery.of(context).size.height,
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
gradient: LinearGradient(
|
||||||
|
colors: [
|
||||||
|
Color.fromRGBO(34, 51, 69, 1),
|
||||||
|
Color.fromRGBO(22, 32, 44, 1),
|
||||||
|
],
|
||||||
|
begin: Alignment.topCenter,
|
||||||
|
end: Alignment.bottomCenter,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const Gap(120),
|
||||||
|
Text('Ofelia Franco-Alcala',
|
||||||
|
style: GoogleFonts.outfit(
|
||||||
|
textStyle: const TextStyle(color: Color.fromRGBO(255, 255, 255, 1), fontSize: 16))),
|
||||||
|
Text('Pharmacy',
|
||||||
|
style: GoogleFonts.outfit(
|
||||||
|
textStyle: const TextStyle(color: Color.fromRGBO(255, 255, 255, 1), fontSize: 32))),
|
||||||
|
const Gap(32),
|
||||||
|
Text('Menu',
|
||||||
|
style: GoogleFonts.outfit(
|
||||||
|
textStyle: const TextStyle(color: Color.fromRGBO(255, 255, 255, 1), fontSize: 32))),
|
||||||
|
const Gap(16),
|
||||||
|
MenuWidget(
|
||||||
|
icon: FontAwesomeIcons.squarePlus,
|
||||||
|
text: 'Add Medicine',
|
||||||
|
),
|
||||||
|
const Gap(16),
|
||||||
|
MenuWidget(
|
||||||
|
icon: FontAwesomeIcons.squarePlus,
|
||||||
|
text: 'Add Medicine',
|
||||||
|
),
|
||||||
|
TextButton(onPressed: () => {signOut()}, child: const Text('Logout'))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
lib/widgets/menu_widget.dart
Normal file
33
lib/widgets/menu_widget.dart
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:gap/gap.dart';
|
||||||
|
|
||||||
|
class MenuWidget extends StatelessWidget {
|
||||||
|
final String? text;
|
||||||
|
final IconData? icon;
|
||||||
|
|
||||||
|
const MenuWidget({
|
||||||
|
super.key,
|
||||||
|
this.text,
|
||||||
|
this.icon,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
width: MediaQuery.of(context).size.width - 32,
|
||||||
|
height: 100,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
color: Colors.grey[200],
|
||||||
|
),
|
||||||
|
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
|
||||||
|
const Gap(32),
|
||||||
|
Icon(icon, size: 32, color: const Color.fromRGBO(34, 51, 69, 1)),
|
||||||
|
const Gap(120),
|
||||||
|
Text(
|
||||||
|
text ?? 'Data',
|
||||||
|
style: TextStyle(fontSize: 16),
|
||||||
|
)
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
||||||
16
pubspec.lock
16
pubspec.lock
|
|
@ -136,6 +136,14 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
font_awesome_flutter:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: font_awesome_flutter
|
||||||
|
sha256: d3a89184101baec7f4600d58840a764d2ef760fe1c5a20ef9e6b0e9b24a07a3a
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "10.8.0"
|
||||||
functions_client:
|
functions_client:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -360,6 +368,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.1"
|
version: "2.4.1"
|
||||||
|
quickalert:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: quickalert
|
||||||
|
sha256: b5d62b1e20b08cc0ff5f40b6da519bdc7a5de6082f13d90572cf4e72eea56c5e
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.1.0"
|
||||||
realtime_client:
|
realtime_client:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ dependencies:
|
||||||
gap: ^3.0.1
|
gap: ^3.0.1
|
||||||
go_router: ^14.6.3
|
go_router: ^14.6.3
|
||||||
supabase_flutter: ^2.8.3
|
supabase_flutter: ^2.8.3
|
||||||
|
quickalert: ^1.1.0
|
||||||
|
font_awesome_flutter: ^10.8.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue