update
This commit is contained in:
parent
cf2ce36f87
commit
50d2cba7f2
9 changed files with 156 additions and 83 deletions
|
|
@ -1,13 +1,11 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:pharmacy_mobile/tables/stocks.dart';
|
||||
import 'package:pharmacy_mobile/widgets/datatable_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/title_widget.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class ListStocksPage extends StatefulWidget {
|
||||
const ListStocksPage({super.key});
|
||||
|
|
@ -20,18 +18,36 @@ class _ListStocksPageState extends State<ListStocksPage> {
|
|||
final _stocks = Stocks();
|
||||
|
||||
late List _stockList = [];
|
||||
bool _isLoading = false;
|
||||
|
||||
List<DataRow> _createRows() {
|
||||
final today = DateTime.now().toUtc();
|
||||
|
||||
return _stockList.map((item) {
|
||||
final dateString = item['expiration_date'];
|
||||
final date = DateTime.parse(dateString);
|
||||
final date = DateTime.parse(dateString).toUtc();
|
||||
final formattedDate = DateFormat('MMMM d, yyyy').format(date);
|
||||
|
||||
return DataRow(cells: [
|
||||
DataCell(Text(item['medicine_name'])),
|
||||
DataCell(Text(item['quantity'].toString())),
|
||||
DataCell(Text(formattedDate)),
|
||||
]);
|
||||
if (date.isBefore(today)) {
|
||||
return DataRow(
|
||||
cells: [
|
||||
DataCell(Text(item['medicine_name'], style: const TextStyle(color: Color.fromRGBO(188, 59, 50, 1)))),
|
||||
DataCell(Text(item['quantity'].toString(), style: const TextStyle(color: Color.fromRGBO(188, 59, 50, 1)))),
|
||||
DataCell(
|
||||
Text(formattedDate,
|
||||
style: const TextStyle(color: Color.fromRGBO(188, 59, 50, 1))), // Highlight expired items
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return DataRow(
|
||||
cells: [
|
||||
DataCell(Text(item['medicine_name'])),
|
||||
DataCell(Text(item['quantity'].toString())),
|
||||
DataCell(Text(formattedDate)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}).toList();
|
||||
}
|
||||
|
||||
|
|
@ -44,8 +60,13 @@ class _ListStocksPageState extends State<ListStocksPage> {
|
|||
}
|
||||
|
||||
void autoRun() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
_stockList = await _stocks.getList();
|
||||
setState(() {});
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -63,14 +84,27 @@ class _ListStocksPageState extends State<ListStocksPage> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: PageBackgroundWidget(
|
||||
child: Column(children: [
|
||||
const Gap(104),
|
||||
const TitleWidget(firstTextSize: 20, secondTextSize: 32),
|
||||
const Gap(32),
|
||||
const TextWidget(text: 'List of Stocks'),
|
||||
const Gap(16),
|
||||
DataTableWidget(column: _createColumns(), row: _createRows()),
|
||||
])));
|
||||
body: PageBackgroundWidget(
|
||||
child: Column(
|
||||
children: [
|
||||
const Gap(104),
|
||||
const TitleWidget(firstTextSize: 20, secondTextSize: 32),
|
||||
const Gap(32),
|
||||
const TextWidget(text: 'List of Stocks'),
|
||||
const Gap(16),
|
||||
if (_isLoading)
|
||||
Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
))
|
||||
else
|
||||
DataTableWidget(
|
||||
column: _createColumns(),
|
||||
row: _createRows(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import 'package:pharmacy_mobile/auth/auth_service.dart';
|
|||
import 'package:pharmacy_mobile/widgets/button_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/input_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:internet_connection_checker/internet_connection_checker.dart';
|
||||
|
|
@ -37,13 +38,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
await _authService.signIn(email, password);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text('Login Successful'),
|
||||
backgroundColor: const Color.fromRGBO(37, 106, 32, 1),
|
||||
elevation: 4.0,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: Duration(seconds: 5),
|
||||
));
|
||||
showNotification(context, 'Login Successful', true);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
|
|
@ -53,24 +48,12 @@ class _LoginPageState extends State<LoginPage> {
|
|||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text('No Internet Connection'),
|
||||
backgroundColor: const Color.fromRGBO(188, 59, 50, 1),
|
||||
elevation: 4.0,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: Duration(seconds: 5),
|
||||
));
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text('Error: $e'),
|
||||
backgroundColor: const Color.fromRGBO(188, 59, 50, 1),
|
||||
elevation: 4.0,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: Duration(seconds: 5),
|
||||
));
|
||||
showNotification(context, 'Error: $e', false);
|
||||
}
|
||||
} finally {
|
||||
setState(() => _isLoading = false);
|
||||
|
|
@ -110,7 +93,8 @@ class _LoginPageState extends State<LoginPage> {
|
|||
child: Container(
|
||||
padding: EdgeInsets.fromLTRB(32, 32, 32, 40),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color.fromRGBO(38, 17, 46, 0.859),
|
||||
// color: const Color.fromRGBO(38, 17, 46, 0.859),
|
||||
color: const Color.fromRGBO(57, 38, 62, 0.9),
|
||||
borderRadius: BorderRadius.all(Radius.circular(16)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
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 'package:pharmacy_mobile/widgets/button_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/input_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/title_widget.dart';
|
||||
|
||||
class RegisterPage extends StatefulWidget {
|
||||
const RegisterPage({super.key});
|
||||
|
|
@ -17,6 +19,9 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
final _emailController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
final _confirmPasswordController = TextEditingController();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
|
||||
bool _isLoading = false;
|
||||
|
||||
Future<void> _signUp() async {
|
||||
final email = _emailController.text;
|
||||
|
|
@ -47,6 +52,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
_emailController.dispose();
|
||||
_passwordController.dispose();
|
||||
_confirmPasswordController.dispose();
|
||||
_focusNode.dispose();
|
||||
_isLoading = false;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
|
@ -54,8 +61,58 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: PageBackgroundWidget(
|
||||
child: Column(
|
||||
children: [],
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Gap(104),
|
||||
const TitleWidget(firstTextSize: 20, secondTextSize: 32),
|
||||
const Gap(32),
|
||||
const TextWidget(text: 'Register'),
|
||||
const Gap(16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 32, right: 32),
|
||||
child: Container(
|
||||
padding: EdgeInsets.fromLTRB(32, 32, 32, 40),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color.fromRGBO(57, 38, 62, 0.9),
|
||||
borderRadius: BorderRadius.all(Radius.circular(16)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color.fromRGBO(0, 0, 0, 0.4), // Subtle shadow to give depth
|
||||
spreadRadius: 0,
|
||||
blurRadius: 4,
|
||||
offset: Offset(0, 2),
|
||||
)
|
||||
]),
|
||||
child: Form(
|
||||
child: Column(
|
||||
children: [
|
||||
InputWidget(label: 'Email', controller: _emailController),
|
||||
const Gap(16),
|
||||
InputWidget(
|
||||
label: 'Password',
|
||||
controller: _passwordController,
|
||||
password: true,
|
||||
),
|
||||
const Gap(16),
|
||||
InputWidget(
|
||||
label: 'Confirm Password',
|
||||
controller: _confirmPasswordController,
|
||||
password: true,
|
||||
),
|
||||
const Gap(40),
|
||||
// TextButton(onPressed: () => {_signIn()}, child: const Text('Login'))
|
||||
if (_isLoading)
|
||||
Center(child: CircularProgressIndicator(color: Colors.white))
|
||||
else
|
||||
ButtonWidget(text: 'Create Account', onPressed: _signUp)
|
||||
],
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue