This commit is contained in:
Patrick Alvin Alcala 2025-01-31 16:35:10 +08:00
parent 7e1ad68433
commit b5151a053d
9 changed files with 118 additions and 39 deletions

View file

@ -15,10 +15,10 @@ class AddGenericsPage extends StatefulWidget {
const AddGenericsPage({super.key}); const AddGenericsPage({super.key});
@override @override
AddGenericsPageState createState() => AddGenericsPageState(); State<AddGenericsPage> createState() => _AddGenericsPageState();
} }
class AddGenericsPageState extends State<AddGenericsPage> { class _AddGenericsPageState extends State<AddGenericsPage> {
// final _formKey = GlobalKey<FormState>(); // final _formKey = GlobalKey<FormState>();
final _refCategories = RefCategories(); final _refCategories = RefCategories();
final _refGenericNames = RefGenericNames(); final _refGenericNames = RefGenericNames();
@ -30,12 +30,6 @@ class AddGenericsPageState extends State<AddGenericsPage> {
late String _selectedCategory = ''; late String _selectedCategory = '';
late String _categoryUUID = ''; late String _categoryUUID = '';
@override
void initState() {
autoRun();
super.initState();
}
void autoRun() async { void autoRun() async {
_categoryList = await _refCategories.getList(); _categoryList = await _refCategories.getList();
} }
@ -50,6 +44,12 @@ class AddGenericsPageState extends State<AddGenericsPage> {
await _refGenericNames.postGeneric(_nameController.text, _categoryUUID); await _refGenericNames.postGeneric(_nameController.text, _categoryUUID);
} }
@override
void initState() {
autoRun();
super.initState();
}
@override @override
void dispose() { void dispose() {
_nameController.dispose(); _nameController.dispose();

View file

@ -17,10 +17,10 @@ class AddMedicinePage extends StatefulWidget {
const AddMedicinePage({super.key}); const AddMedicinePage({super.key});
@override @override
AddMedicinePageState createState() => AddMedicinePageState(); State<AddMedicinePage> createState() => _AddMedicinePageState();
} }
class AddMedicinePageState extends State<AddMedicinePage> { class _AddMedicinePageState extends State<AddMedicinePage> {
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
// final _authService = AuthService(); // final _authService = AuthService();
final _refGenericNames = RefGenericNames(); final _refGenericNames = RefGenericNames();
@ -40,12 +40,6 @@ class AddMedicinePageState extends State<AddMedicinePage> {
late List _manufactorerList = []; late List _manufactorerList = [];
late String _selectedManufactorer = ''; late String _selectedManufactorer = '';
@override
void initState() {
autoRun();
super.initState();
}
void autoRun() async { void autoRun() async {
_genericNameList = await _refGenericNames.getList(); _genericNameList = await _refGenericNames.getList();
_typeList = await _refTypes.getList(); _typeList = await _refTypes.getList();
@ -79,6 +73,12 @@ class AddMedicinePageState extends State<AddMedicinePage> {
await _refMedicines.postMedicine(medName, medGenericUUID, medManufactorerUUID, medTypeUUID); await _refMedicines.postMedicine(medName, medGenericUUID, medManufactorerUUID, medTypeUUID);
} }
@override
void initState() {
autoRun();
super.initState();
}
@override @override
void dispose() { void dispose() {
_nameController.dispose(); _nameController.dispose();

View file

@ -17,7 +17,7 @@ class AddStockPage extends StatefulWidget {
const AddStockPage({super.key}); const AddStockPage({super.key});
@override @override
_AddStockPageState createState() => _AddStockPageState(); State<AddStockPage> createState() => _AddStockPageState();
} }
class _AddStockPageState extends State<AddStockPage> { class _AddStockPageState extends State<AddStockPage> {

View file

@ -16,7 +16,7 @@ class AddTypePage extends StatefulWidget {
const AddTypePage({super.key}); const AddTypePage({super.key});
@override @override
_AddTypePageState createState() => _AddTypePageState(); State<AddTypePage> createState() => _AddTypePageState();
} }
class _AddTypePageState extends State<AddTypePage> { class _AddTypePageState extends State<AddTypePage> {

View file

@ -1,26 +1,63 @@
import 'dart:developer';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.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/page_background_widget.dart';
import 'package:pharmacy_mobile/widgets/text_widget.dart'; import 'package:pharmacy_mobile/widgets/text_widget.dart';
import 'package:pharmacy_mobile/widgets/title_widget.dart'; import 'package:pharmacy_mobile/widgets/title_widget.dart';
import 'package:intl/intl.dart';
class ListStocksPage extends StatefulWidget { class ListStocksPage extends StatefulWidget {
const ListStocksPage({super.key}); const ListStocksPage({super.key});
@override @override
_ListStocksPageState createState() => _ListStocksPageState(); State<ListStocksPage> createState() => _ListStocksPageState();
} }
class _ListStocksPageState extends State<ListStocksPage> { class _ListStocksPageState extends State<ListStocksPage> {
final _stocks = Stocks();
late List _stockList = [];
List<DataRow> _createRows() { List<DataRow> _createRows() {
return [ return _stockList.map((item) {
DataRow(cells: [DataCell(Text('#100')), DataCell(Text('Flutter Basics')), DataCell(Text('David John'))]), final dateString = item['expiration_date'];
DataRow(cells: [DataCell(Text('#101')), DataCell(Text('Dart Internals')), DataCell(Text('Alex Wick'))]) final date = DateTime.parse(dateString);
]; final formattedDate = DateFormat('MMMM d, yyyy').format(date);
return DataRow(cells: [
DataCell(Text(item['medicine_name'])),
DataCell(Text(item['quantity'].toString())),
DataCell(Text(formattedDate)),
]);
}).toList();
} }
List<DataColumn> _createColumns() { List<DataColumn> _createColumns() {
return [DataColumn(label: Text('ID')), DataColumn(label: Text('Book')), DataColumn(label: Text('Author'))]; return [
DataColumn(label: Text('Medicine')),
DataColumn(label: Text('Quantity')),
DataColumn(label: Text('Expiration'))
];
}
void autoRun() async {
_stockList = await _stocks.getList();
setState(() {});
}
@override
void initState() {
autoRun();
super.initState();
}
@override
void dispose() {
_stockList = [];
super.dispose();
} }
@override @override
@ -33,15 +70,7 @@ class _ListStocksPageState extends State<ListStocksPage> {
const Gap(32), const Gap(32),
const TextWidget(text: 'List of Stocks'), const TextWidget(text: 'List of Stocks'),
const Gap(16), const Gap(16),
DataTable( DataTableWidget(column: _createColumns(), row: _createRows()),
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 1.0),
borderRadius: BorderRadius.circular(8.0),
color: Color.fromARGB(255, 240, 240, 240),
),
columns: _createColumns(),
rows: _createRows(),
)
]))); ])));
} }
} }

View file

@ -137,7 +137,7 @@ class _LoginPageState extends State<LoginPage> {
password: true, password: true,
), ),
), ),
const Gap(24), const Gap(40),
// TextButton(onPressed: () => {_signIn()}, child: const Text('Login')) // TextButton(onPressed: () => {_signIn()}, child: const Text('Login'))
if (_isLoading) if (_isLoading)
Center(child: CircularProgressIndicator(color: Colors.white)) Center(child: CircularProgressIndicator(color: Colors.white))

View file

@ -64,7 +64,7 @@ class MainPage extends StatelessWidget {
icon: FontAwesomeIcons.listCheck, icon: FontAwesomeIcons.listCheck,
text: 'List of Stocks', text: 'List of Stocks',
onPressed: () => {context.push('/liststocks')}), onPressed: () => {context.push('/liststocks')}),
const Gap(32), const Gap(40),
// TextButton(onPressed: () => {_signOut()}, child: const Text('Logout')), // TextButton(onPressed: () => {_signOut()}, child: const Text('Logout')),
ButtonWidget( ButtonWidget(
text: 'Logout', text: 'Logout',

View file

@ -1,13 +1,40 @@
import 'dart:developer';
import 'package:supabase_flutter/supabase_flutter.dart'; import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:uuid/uuid.dart'; import 'package:uuid/uuid.dart';
class Stocks { class Stocks {
final SupabaseClient _supabase = Supabase.instance.client; final SupabaseClient _supabase = Supabase.instance.client;
// Future<List> getList() async { Future<List> getList() async {
// final data = await _supabase.from('stocks').select('type_name').order('type_name', ascending: true); List<Map<String, dynamic>> stockData = [];
// return data.toList();
// } final data = await _supabase.from('stocks').select('*');
stockData = data;
List<Map<String, dynamic>> result = [];
for (var stock in stockData) {
final muuid = stock['ref_medicines_uuid'];
try {
final medicineNameResult =
await _supabase.from('ref_medicines').select('medicine_name').eq('ref_medicines_uuid', muuid);
if (medicineNameResult.isNotEmpty) {
final medicineName = medicineNameResult[0]['medicine_name'];
result.add({
'medicine_name': medicineName,
'quantity': stock['quantity'],
'expiration_date': stock['expiration_date'],
});
}
} catch (e) {
return [];
}
}
return result;
}
// Future<String> getUUID(String name) async { // Future<String> getUUID(String name) async {
// final data = await _supabase.from('ref_types').select('ref_types_uuid').eq('type_name', name); // final data = await _supabase.from('ref_types').select('ref_types_uuid').eq('type_name', name);

View file

@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class DataTableWidget extends StatelessWidget {
final List<DataColumn> column;
final List<DataRow> row;
const DataTableWidget({super.key, required this.column, required this.row});
@override
Widget build(BuildContext context) {
return DataTable(
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 1.0),
borderRadius: BorderRadius.circular(12),
color: Color.fromARGB(255, 240, 240, 240),
),
headingTextStyle: GoogleFonts.outfit(textStyle: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
dataTextStyle: GoogleFonts.outfit(textStyle: const TextStyle(fontSize: 14)),
columns: column,
rows: row,
);
}
}