pharmacy_mobile/lib/pages/login_page.dart
2025-01-22 13:14:06 +08:00

165 lines
5.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:gap/gap.dart';
import 'package:pharmacy_mobile/auth/auth_service.dart';
import 'package:pharmacy_mobile/main.dart';
import 'dart:developer';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final _authService = AuthService();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
Future<void> _signIn() async {
final email = _emailController.text;
final password = _passwordController.text;
try {
await _authService.signIn(email, password);
log('message');
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Error: $e')));
}
}
// if (mounted) {
// context.showSnackBar('Check your email for a login link!');
// _emailController.clear();
// }
}
@override
void dispose() {
_emailController.dispose();
_passwordController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
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(
mainAxisAlignment: MainAxisAlignment.start,
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('Login',
style: GoogleFonts.outfit(
textStyle: const TextStyle(color: Color.fromRGBO(255, 255, 255, 1), fontSize: 32))),
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: [
TextFormField(
controller: _emailController,
decoration: InputDecoration(
labelText: 'Email',
border: OutlineInputBorder(),
),
style: TextStyle(color: Colors.white),
),
const Gap(8),
TextFormField(
controller: _passwordController,
decoration: InputDecoration(
labelText: 'Password',
border: OutlineInputBorder(),
),
style: TextStyle(color: Colors.white),
),
const Gap(16),
TextButton(onPressed: () => {_signIn()}, child: 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'),
// ),
// ],
// ),
// ),
// )
// )
],
),
),
));
}
}