This commit is contained in:
Patrick Alvin Alcala 2025-02-10 17:02:37 +08:00
parent 5840df0879
commit b45cf8bd73
11 changed files with 222 additions and 34 deletions

View file

@ -1,8 +1,12 @@
import 'dart:developer';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:pharmacy_mobile/tables/stocks.dart';
import 'package:pharmacy_mobile/tables/storage.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';
@ -17,6 +21,7 @@ class ListStocksPage extends StatefulWidget {
class _ListStocksPageState extends State<ListStocksPage> {
final _stocks = Stocks();
final _storage = Storage();
late List _stockList = [];
bool _isLoading = false;
@ -54,9 +59,9 @@ class _ListStocksPageState extends State<ListStocksPage> {
List<DataColumn> _createColumns() {
return [
DataColumn(label: Text('Medicine')),
DataColumn(label: Text('Quantity')),
DataColumn(label: Text('Expiration'))
const DataColumn(label: Text('Medicine')),
const DataColumn(label: Text('Quantity')),
const DataColumn(label: Text('Expiration'))
];
}
@ -64,7 +69,13 @@ class _ListStocksPageState extends State<ListStocksPage> {
setState(() {
_isLoading = true;
});
_stockList = await _stocks.getList();
// _stockList = await _stocks.getList();
// final ff = File('assets/ph_logo.webp');
// await _storage.uploadFile(ff);
final aa = await _storage.getList();
// final aa = await _storage.createBucket('aa');
log(aa.toString());
setState(() {
_isLoading = false;
});
@ -99,7 +110,6 @@ class _ListStocksPageState extends State<ListStocksPage> {
color: Color.fromRGBO(255, 255, 255, 1),
))
else if (_stockList.isEmpty)
// TextWidget(text: 'No Stock Listed')
Container(
decoration: BoxDecoration(
border: Border.all(color: const Color.fromRGBO(205, 59, 208, 0.702), width: 2),

View file

@ -1,39 +1,53 @@
import 'dart:developer';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:uuid/uuid.dart';
class Stocks {
final SupabaseClient _supabase = Supabase.instance.client;
// Future<List> getList() async {
// List<Map<String, dynamic>> stockData = [];
// 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<List> getList() async {
List<Map<String, dynamic>> stockData = [];
final data = await _supabase.from('stocks').select('*');
stockData = data;
final data = await _supabase.from('stocks').select('ref_medicines(medicine_name), expiration_date, quantity');
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 [];
}
for (var item in data) {
stockData.add({
'medicine_name': item['ref_medicines']['medicine_name'],
'quantity': item['quantity'].toString(),
'expiration_date': item['expiration_date'],
});
}
return result;
return stockData;
}
// Future<String> getUUID(String name) async {

37
lib/tables/storage.dart Normal file
View file

@ -0,0 +1,37 @@
import 'dart:developer';
import 'dart:io';
import 'package:supabase_flutter/supabase_flutter.dart';
class Storage {
final SupabaseClient _supabase = Supabase.instance.client;
Future<String> createBucket(String name) async {
try {
final response = await _supabase.storage.createBucket(name);
return response;
} catch (e, stackTrace) {
log('Error creating bucket: $e', stackTrace: stackTrace);
rethrow;
}
}
Future<List> getList() async {
try {
final response = await _supabase.storage.listBuckets();
return response;
} catch (e, stackTrace) {
log('Error getting list: $e', stackTrace: stackTrace);
rethrow;
}
}
Future<void> uploadFile(File file) async {
try {
final fileName = file.path.split('/').last;
await _supabase.storage.from('images').upload(fileName, file);
} catch (e) {
log('Error getting list: $e');
rethrow;
}
}
}

View file

@ -10,12 +10,15 @@ class DataTableWidget extends StatelessWidget {
Widget build(BuildContext context) {
return DataTable(
decoration: BoxDecoration(
border: Border.all(color: const Color.fromRGBO(0, 0, 0, 1), width: 1.0),
border: Border.all(color: const Color.fromARGB(255, 255, 255, 255), width: 1.0),
borderRadius: BorderRadius.circular(12),
color: const Color.fromARGB(255, 240, 240, 240),
color: const Color.fromARGB(144, 82, 42, 82),
),
headingTextStyle: GoogleFonts.outfit(textStyle: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
dataTextStyle: GoogleFonts.outfit(textStyle: const TextStyle(fontSize: 14)),
headingTextStyle: GoogleFonts.outfit(
textStyle:
const TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: Color.fromRGBO(255, 255, 255, 1))),
dataTextStyle:
GoogleFonts.outfit(textStyle: const TextStyle(fontSize: 14, color: Color.fromRGBO(255, 255, 255, 1))),
columns: column,
rows: row,
);