diff --git a/lib/pages/list_stocks.dart b/lib/pages/list_stocks.dart index 20eb64e..560d955 100644 --- a/lib/pages/list_stocks.dart +++ b/lib/pages/list_stocks.dart @@ -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 { final _stocks = Stocks(); + final _storage = Storage(); late List _stockList = []; bool _isLoading = false; @@ -54,9 +59,9 @@ class _ListStocksPageState extends State { List _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 { 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 { 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), diff --git a/lib/tables/stocks.dart b/lib/tables/stocks.dart index a1f4ae3..1ede3be 100644 --- a/lib/tables/stocks.dart +++ b/lib/tables/stocks.dart @@ -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 getList() async { + // List> stockData = []; + + // final data = await _supabase.from('stocks').select('*'); + // stockData = data; + + // List> 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 getList() async { List> 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> 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 getUUID(String name) async { diff --git a/lib/tables/storage.dart b/lib/tables/storage.dart new file mode 100644 index 0000000..9ce22e6 --- /dev/null +++ b/lib/tables/storage.dart @@ -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 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 getList() async { + try { + final response = await _supabase.storage.listBuckets(); + return response; + } catch (e, stackTrace) { + log('Error getting list: $e', stackTrace: stackTrace); + rethrow; + } + } + + Future 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; + } + } +} diff --git a/lib/widgets/datatable_widget.dart b/lib/widgets/datatable_widget.dart index 8f14021..7f0cc2b 100644 --- a/lib/widgets/datatable_widget.dart +++ b/lib/widgets/datatable_widget.dart @@ -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, ); diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 3792af4..e12c657 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,10 +6,14 @@ #include "generated_plugin_registrant.h" +#include #include #include 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 = fl_plugin_registry_get_registrar_for_plugin(registry, "GtkPlugin"); gtk_plugin_register_with_registrar(gtk_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 5d07423..4453582 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + file_selector_linux gtk url_launcher_linux ) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 68d7312..38eb4e6 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -7,6 +7,7 @@ import Foundation import app_links import connectivity_plus +import file_selector_macos import path_provider_foundation import shared_preferences_foundation import url_launcher_macos @@ -14,6 +15,7 @@ import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin")) ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin")) + FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) diff --git a/pubspec.lock b/pubspec.lock index cf6cf13..80ead7e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -97,6 +97,14 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: transitive description: @@ -145,6 +153,38 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: transitive description: @@ -166,6 +206,14 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: "direct dev" description: flutter @@ -248,6 +296,70 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 4e22f5c..c40612d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,6 +19,7 @@ dependencies: uuid: ^4.5.1 intl: ^0.20.2 internet_connection_checker: ^3.0.1 + image_picker: ^1.1.2 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 9eb38ec..ab04550 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -8,6 +8,7 @@ #include #include +#include #include void RegisterPlugins(flutter::PluginRegistry* registry) { @@ -15,6 +16,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("AppLinksPluginCApi")); ConnectivityPlusWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); + FileSelectorWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FileSelectorWindows")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 64c0dfb..d1bae2b 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -5,6 +5,7 @@ list(APPEND FLUTTER_PLUGIN_LIST app_links connectivity_plus + file_selector_windows url_launcher_windows )