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:flutter/material.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:pharmacy_mobile/tables/stocks.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/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';
@ -17,6 +21,7 @@ class ListStocksPage extends StatefulWidget {
class _ListStocksPageState extends State<ListStocksPage> { class _ListStocksPageState extends State<ListStocksPage> {
final _stocks = Stocks(); final _stocks = Stocks();
final _storage = Storage();
late List _stockList = []; late List _stockList = [];
bool _isLoading = false; bool _isLoading = false;
@ -54,9 +59,9 @@ class _ListStocksPageState extends State<ListStocksPage> {
List<DataColumn> _createColumns() { List<DataColumn> _createColumns() {
return [ return [
DataColumn(label: Text('Medicine')), const DataColumn(label: Text('Medicine')),
DataColumn(label: Text('Quantity')), const DataColumn(label: Text('Quantity')),
DataColumn(label: Text('Expiration')) const DataColumn(label: Text('Expiration'))
]; ];
} }
@ -64,7 +69,13 @@ class _ListStocksPageState extends State<ListStocksPage> {
setState(() { setState(() {
_isLoading = true; _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(() { setState(() {
_isLoading = false; _isLoading = false;
}); });
@ -99,7 +110,6 @@ class _ListStocksPageState extends State<ListStocksPage> {
color: Color.fromRGBO(255, 255, 255, 1), color: Color.fromRGBO(255, 255, 255, 1),
)) ))
else if (_stockList.isEmpty) else if (_stockList.isEmpty)
// TextWidget(text: 'No Stock Listed')
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all(color: const Color.fromRGBO(205, 59, 208, 0.702), width: 2), 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: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 {
// 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 { Future<List> getList() async {
List<Map<String, dynamic>> stockData = []; List<Map<String, dynamic>> stockData = [];
final data = await _supabase.from('stocks').select('*'); final data = await _supabase.from('stocks').select('ref_medicines(medicine_name), expiration_date, quantity');
stockData = data;
List<Map<String, dynamic>> result = []; for (var item in data) {
stockData.add({
for (var stock in stockData) { 'medicine_name': item['ref_medicines']['medicine_name'],
final muuid = stock['ref_medicines_uuid']; 'quantity': item['quantity'].toString(),
'expiration_date': item['expiration_date'],
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 stockData;
}
}
return result;
} }
// Future<String> getUUID(String name) async { // 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) { Widget build(BuildContext context) {
return DataTable( return DataTable(
decoration: BoxDecoration( 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), 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)), headingTextStyle: GoogleFonts.outfit(
dataTextStyle: GoogleFonts.outfit(textStyle: const TextStyle(fontSize: 14)), 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, columns: column,
rows: row, rows: row,
); );

View file

@ -6,10 +6,14 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <file_selector_linux/file_selector_plugin.h>
#include <gtk/gtk_plugin.h> #include <gtk/gtk_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h> #include <url_launcher_linux/url_launcher_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) gtk_registrar = g_autoptr(FlPluginRegistrar) gtk_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin"); fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin");
gtk_plugin_register_with_registrar(gtk_registrar); gtk_plugin_register_with_registrar(gtk_registrar);

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
gtk gtk
url_launcher_linux url_launcher_linux
) )

View file

@ -7,6 +7,7 @@ import Foundation
import app_links import app_links
import connectivity_plus import connectivity_plus
import file_selector_macos
import path_provider_foundation import path_provider_foundation
import shared_preferences_foundation import shared_preferences_foundation
import url_launcher_macos import url_launcher_macos
@ -14,6 +15,7 @@ import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin")) AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin")) ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))

View file

@ -97,6 +97,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: "7caf6a750a0c04effbb52a676dce9a4a592e10ad35c34d6d2d0e4811160d5670"
url: "https://pub.dev"
source: hosted
version: "0.3.4+2"
crypto: crypto:
dependency: transitive dependency: transitive
description: description:
@ -145,6 +153,38 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "7.0.1" version: "7.0.1"
file_selector_linux:
dependency: transitive
description:
name: file_selector_linux
sha256: "54cbbd957e1156d29548c7d9b9ec0c0ebb6de0a90452198683a7d23aed617a33"
url: "https://pub.dev"
source: hosted
version: "0.9.3+2"
file_selector_macos:
dependency: transitive
description:
name: file_selector_macos
sha256: "271ab9986df0c135d45c3cdb6bd0faa5db6f4976d3e4b437cf7d0f258d941bfc"
url: "https://pub.dev"
source: hosted
version: "0.9.4+2"
file_selector_platform_interface:
dependency: transitive
description:
name: file_selector_platform_interface
sha256: a3994c26f10378a039faa11de174d7b78eb8f79e4dd0af2a451410c1a5c3f66b
url: "https://pub.dev"
source: hosted
version: "2.6.2"
file_selector_windows:
dependency: transitive
description:
name: file_selector_windows
sha256: "8f5d2f6590d51ecd9179ba39c64f722edc15226cc93dcc8698466ad36a4a85a4"
url: "https://pub.dev"
source: hosted
version: "0.9.3+3"
fixnum: fixnum:
dependency: transitive dependency: transitive
description: description:
@ -166,6 +206,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "5.0.0" version: "5.0.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: "615a505aef59b151b46bbeef55b36ce2b6ed299d160c51d84281946f0aa0ce0e"
url: "https://pub.dev"
source: hosted
version: "2.0.24"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@ -248,6 +296,70 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.1.2" version: "4.1.2"
image_picker:
dependency: "direct main"
description:
name: image_picker
sha256: "021834d9c0c3de46bf0fe40341fa07168407f694d9b2bb18d532dc1261867f7a"
url: "https://pub.dev"
source: hosted
version: "1.1.2"
image_picker_android:
dependency: transitive
description:
name: image_picker_android
sha256: b62d34a506e12bb965e824b6db4fbf709ee4589cf5d3e99b45ab2287b008ee0c
url: "https://pub.dev"
source: hosted
version: "0.8.12+20"
image_picker_for_web:
dependency: transitive
description:
name: image_picker_for_web
sha256: "717eb042ab08c40767684327be06a5d8dbb341fe791d514e4b92c7bbe1b7bb83"
url: "https://pub.dev"
source: hosted
version: "3.0.6"
image_picker_ios:
dependency: transitive
description:
name: image_picker_ios
sha256: "05da758e67bc7839e886b3959848aa6b44ff123ab4b28f67891008afe8ef9100"
url: "https://pub.dev"
source: hosted
version: "0.8.12+2"
image_picker_linux:
dependency: transitive
description:
name: image_picker_linux
sha256: "4ed1d9bb36f7cd60aa6e6cd479779cc56a4cb4e4de8f49d487b1aaad831300fa"
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
image_picker_macos:
dependency: transitive
description:
name: image_picker_macos
sha256: "1b90ebbd9dcf98fb6c1d01427e49a55bd96b5d67b8c67cf955d60a5de74207c1"
url: "https://pub.dev"
source: hosted
version: "0.2.1+2"
image_picker_platform_interface:
dependency: transitive
description:
name: image_picker_platform_interface
sha256: "886d57f0be73c4b140004e78b9f28a8914a09e50c2d816bdd0520051a71236a0"
url: "https://pub.dev"
source: hosted
version: "2.10.1"
image_picker_windows:
dependency: transitive
description:
name: image_picker_windows
sha256: "6ad07afc4eb1bc25f3a01084d28520496c4a3bb0cb13685435838167c9dcedeb"
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
internet_connection_checker: internet_connection_checker:
dependency: "direct main" dependency: "direct main"
description: description:

View file

@ -19,6 +19,7 @@ dependencies:
uuid: ^4.5.1 uuid: ^4.5.1
intl: ^0.20.2 intl: ^0.20.2
internet_connection_checker: ^3.0.1 internet_connection_checker: ^3.0.1
image_picker: ^1.1.2
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View file

@ -8,6 +8,7 @@
#include <app_links/app_links_plugin_c_api.h> #include <app_links/app_links_plugin_c_api.h>
#include <connectivity_plus/connectivity_plus_windows_plugin.h> #include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <file_selector_windows/file_selector_windows.h>
#include <url_launcher_windows/url_launcher_windows.h> #include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
@ -15,6 +16,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("AppLinksPluginCApi")); registry->GetRegistrarForPlugin("AppLinksPluginCApi"));
ConnectivityPlusWindowsPluginRegisterWithRegistrar( ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
UrlLauncherWindowsRegisterWithRegistrar( UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows")); registry->GetRegistrarForPlugin("UrlLauncherWindows"));
} }

View file

@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
app_links app_links
connectivity_plus connectivity_plus
file_selector_windows
url_launcher_windows url_launcher_windows
) )