diff --git a/lib/controller/cart_controller.dart b/lib/controller/cart_controller.dart index 8ef9a56..26c0f78 100644 --- a/lib/controller/cart_controller.dart +++ b/lib/controller/cart_controller.dart @@ -1,26 +1,29 @@ import 'package:get/get.dart'; import '../models/product_model.dart'; -import 'package:collection/collection.dart'; - import '../models/product_model1.dart'; class CartController extends GetxController { - var cartList = [].obs; var cartCount = 0.obs; - var totalPrice = 0.0.obs; var subtotal = 0.0.obs; var gstTotal = 0.0.obs; var grandTotal = 0.0.obs; - // Add item to cart + // Track the selected products + var selectedProducts = [].obs; + + @override + void onInit() { + super.onInit(); + // Initialize the cart list or other initializations if needed + initializeSelections(); + } + void addToCart(Product product) { var existingProduct = cartList.firstWhereOrNull((p) => p.id == product.id); if (existingProduct != null) { - // Update quantity if already in cart existingProduct.quantity++; } else { - // Add new product to cart cartList.add(product); } cartCount.value = cartList.length; @@ -31,7 +34,7 @@ class CartController extends GetxController { double subTotal = 0.0; double gstTotalAmount = 0.0; - for (var product in cartList) { + for (var product in selectedProducts) { subTotal += product.price * product.quantity; gstTotalAmount += (product.price * product.quantity * (product.gst / 100)); } @@ -41,28 +44,135 @@ class CartController extends GetxController { grandTotal.value = subtotal.value + gstTotal.value; } - // Increase the quantity of a product void increaseQuantity(Product product) { final index = cartList.indexWhere((item) => item.id == product.id); if (index != -1) { cartList[index].quantity++; - updateTotalPrice(); + if (selectedProducts.contains(cartList[index])) { + updateTotalPrice(); + } } } - // Decrease the quantity of a product void decreaseQuantity(Product product) { final index = cartList.indexWhere((item) => item.id == product.id); if (index != -1 && cartList[index].quantity > 1) { cartList[index].quantity--; - updateTotalPrice(); + if (selectedProducts.contains(cartList[index])) { + updateTotalPrice(); + } } } - // Remove item from cart void removeFromCart(Product product) { cartList.removeWhere((item) => item.id == product.id); + selectedProducts.remove(product); cartCount.value = cartList.length; updateTotalPrice(); } + + void toggleProductSelection(Product product, bool isSelected) { + if (isSelected) { + if (!selectedProducts.contains(product)) { + selectedProducts.add(product); + } + } else { + selectedProducts.remove(product); + } + updateTotalPrice(); + } + + void selectAllProducts(bool selectAll) { + if (selectAll) { + selectedProducts.assignAll(cartList); + } else { + selectedProducts.clear(); + } + updateTotalPrice(); + } + + void initializeSelections() { + selectAllProducts(true); + } } + + + + + +// import 'package:get/get.dart'; +// import '../models/product_model.dart'; +// import 'package:collection/collection.dart'; +// +// import '../models/product_model1.dart'; +// +// class CartController extends GetxController { +// +// var cartList = [].obs; +// var cartCount = 0.obs; +// var subtotal = 0.0.obs; +// var gstTotal = 0.0.obs; +// var grandTotal = 0.0.obs; +// +// // Add item to cart +// void addToCart(Product product) { +// var existingProduct = cartList.firstWhereOrNull((p) => p.id == product.id); +// if (existingProduct != null) { +// // Update quantity if already in cart +// existingProduct.quantity++; +// } else { +// // Add new product to cart +// cartList.add(product); +// } +// cartCount.value = cartList.length; +// updateTotalPrice(); +// } +// +// void updateTotalPrice() { +// double subTotal = 0.0; +// double gstTotalAmount = 0.0; +// +// for (var product in cartList.where((p) => p.selected)) { +// subTotal += product.price * product.quantity; +// gstTotalAmount += (product.price * product.quantity * (product.gst / 100)); +// } +// +// subtotal.value = subTotal; +// gstTotal.value = gstTotalAmount; +// grandTotal.value = subtotal.value + gstTotal.value; +// } +// +// // Increase the quantity of a product +// void increaseQuantity(Product product) { +// final index = cartList.indexWhere((item) => item.id == product.id); +// if (index != -1) { +// cartList[index].quantity++; +// updateTotalPrice(); +// } +// } +// +// // Decrease the quantity of a product +// void decreaseQuantity(Product product) { +// final index = cartList.indexWhere((item) => item.id == product.id); +// if (index != -1 && cartList[index].quantity > 1) { +// cartList[index].quantity--; +// updateTotalPrice(); +// } +// } +// +// // Remove item from cart +// void removeFromCart(Product product) { +// cartList.removeWhere((item) => item.id == product.id); +// cartCount.value = cartList.length; +// updateTotalPrice(); +// } +// +// // Toggle product selection +// void toggleProductSelection(Product product, bool isSelected) { +// final index = cartList.indexWhere((item) => item.id == product.id); +// if (index != -1) { +// cartList[index].selected = isSelected; +// updateTotalPrice(); +// } +// } +// } diff --git a/lib/screens/order/checkout_screen.dart b/lib/screens/order/checkout_screen.dart index e22c0dc..d8e58a0 100644 --- a/lib/screens/order/checkout_screen.dart +++ b/lib/screens/order/checkout_screen.dart @@ -121,7 +121,7 @@ class _CheckoutScreenState extends State { void _onPlaceOrder() async { try { // Map the cart items (Product) to OrderItem objects - List orderItems = _cartController.cartList.map((product) { + List orderItems = _cartController.selectedProducts.map((product) { return OrderItem( id: product.id, name: product.name, @@ -135,6 +135,7 @@ class _CheckoutScreenState extends State { createdAt: product.createdAt, updatedAt: product.createdAt, count: product.quantity, + //category:product.category, category:Category(id: product.category.id, categoryName: product.category.categoryName), // brand:product.brand, @@ -342,12 +343,12 @@ class _CheckoutScreenState extends State { child: Padding( padding: EdgeInsets.all(Get.width * 0.02), child: ListView.builder( - itemCount: _cartController.cartList.length, + itemCount: _cartController.selectedProducts.length, itemBuilder: (context, index) { final cartItem = _cartController.cartList[index]; return ProductCard( - productModel:_cartController.cartList[index] , + productModel:_cartController.selectedProducts[index] , isCheckout: true, quantity: _cartController.cartList[0].quantity, diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 2d07bbf..8c7a0b8 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -7,6 +7,11 @@ import Foundation import device_info_plus import file_selector_macos +import firebase_analytics +import firebase_core +import firebase_crashlytics +import firebase_messaging +import flutter_local_notifications import path_provider_foundation import shared_preferences_foundation import syncfusion_pdfviewer_macos @@ -15,6 +20,11 @@ import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) + FLTFirebaseAnalyticsPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAnalyticsPlugin")) + FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) + FLTFirebaseCrashlyticsPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCrashlyticsPlugin")) + FLTFirebaseMessagingPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseMessagingPlugin")) + FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SyncfusionFlutterPdfViewerPlugin.register(with: registry.registrar(forPlugin: "SyncfusionFlutterPdfViewerPlugin")) diff --git a/pubspec.lock b/pubspec.lock index cd75b92..80a9be6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,14 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _flutterfire_internals: + dependency: transitive + description: + name: _flutterfire_internals + sha256: ddc6f775260b89176d329dee26f88b9469ef46aa3228ff6a0b91caf2b2989692 + url: "https://pub.dev" + source: hosted + version: "1.3.42" args: dependency: transitive description: @@ -97,6 +105,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.8" + dbus: + dependency: transitive + description: + name: dbus + sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac" + url: "https://pub.dev" + source: hosted + version: "0.7.10" device_info_plus: dependency: transitive description: @@ -185,6 +201,94 @@ packages: url: "https://pub.dev" source: hosted version: "0.9.3+2" + firebase_analytics: + dependency: "direct main" + description: + name: firebase_analytics + sha256: "7b5ae39d853ead76f9d030dc23389bfec4ea826d7cccb4eea4873dcb0cdd172b" + url: "https://pub.dev" + source: hosted + version: "11.3.1" + firebase_analytics_platform_interface: + dependency: transitive + description: + name: firebase_analytics_platform_interface + sha256: "0205e05bb37abd29d5dec5cd89aeb04f3f58bf849aad21dd938be0507d52a40c" + url: "https://pub.dev" + source: hosted + version: "4.2.3" + firebase_analytics_web: + dependency: transitive + description: + name: firebase_analytics_web + sha256: "434807f8b30526e21cc062410c28ee5c6680a13626c4443b5ffede29f84b0c74" + url: "https://pub.dev" + source: hosted + version: "0.5.10" + firebase_core: + dependency: "direct main" + description: + name: firebase_core + sha256: "40921de9795fbf5887ed5c0adfdf4972d5a8d7ae7e1b2bb98dea39bc02626a88" + url: "https://pub.dev" + source: hosted + version: "3.4.1" + firebase_core_platform_interface: + dependency: transitive + description: + name: firebase_core_platform_interface + sha256: f7d7180c7f99babd4b4c517754d41a09a4943a0f7a69b65c894ca5c68ba66315 + url: "https://pub.dev" + source: hosted + version: "5.2.1" + firebase_core_web: + dependency: transitive + description: + name: firebase_core_web + sha256: f4ee170441ca141c5f9ee5ad8737daba3ee9c8e7efb6902aee90b4fbd178ce25 + url: "https://pub.dev" + source: hosted + version: "2.18.0" + firebase_crashlytics: + dependency: "direct main" + description: + name: firebase_crashlytics + sha256: c4fdbb14ba6f36794f89dc27fb5c759c9cc67ecbaeb079edc4dba515bbf9f555 + url: "https://pub.dev" + source: hosted + version: "4.1.1" + firebase_crashlytics_platform_interface: + dependency: transitive + description: + name: firebase_crashlytics_platform_interface + sha256: "891d6f7ba4b93672d0e1265f27b6a9dccd56ba2cc30ce6496586b32d1d8770ac" + url: "https://pub.dev" + source: hosted + version: "3.6.42" + firebase_messaging: + dependency: "direct main" + description: + name: firebase_messaging + sha256: cc02c4afd6510cd84586020670140c4a23fbe52af16cd260ccf8ede101bb8d1b + url: "https://pub.dev" + source: hosted + version: "15.1.1" + firebase_messaging_platform_interface: + dependency: transitive + description: + name: firebase_messaging_platform_interface + sha256: d8a4984635f09213302243ea670fe5c42f3261d7d8c7c0a5f7dcd5d6c84be459 + url: "https://pub.dev" + source: hosted + version: "4.5.44" + firebase_messaging_web: + dependency: transitive + description: + name: firebase_messaging_web + sha256: "258b9d637965db7855299b123533609ed95e52350746a723dfd1d8d6f3fac678" + url: "https://pub.dev" + source: hosted + version: "3.9.0" fixnum: dependency: transitive description: @@ -206,6 +310,30 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.2" + flutter_local_notifications: + dependency: "direct main" + description: + name: flutter_local_notifications + sha256: c500d5d9e7e553f06b61877ca6b9c8b92c570a4c8db371038702e8ce57f8a50f + url: "https://pub.dev" + source: hosted + version: "17.2.2" + flutter_local_notifications_linux: + dependency: transitive + description: + name: flutter_local_notifications_linux + sha256: c49bd06165cad9beeb79090b18cd1eb0296f4bf4b23b84426e37dd7c027fc3af + url: "https://pub.dev" + source: hosted + version: "4.0.1" + flutter_local_notifications_platform_interface: + dependency: transitive + description: + name: flutter_local_notifications_platform_interface + sha256: "85f8d07fe708c1bdcf45037f2c0109753b26ae077e9d9e899d55971711a4ea66" + url: "https://pub.dev" + source: hosted + version: "7.2.0" flutter_plugin_android_lifecycle: dependency: transitive description: @@ -717,6 +845,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.0" + timezone: + dependency: transitive + description: + name: timezone + sha256: "2236ec079a174ce07434e89fcd3fcda430025eb7692244139a9cf54fdcf1fc7d" + url: "https://pub.dev" + source: hosted + version: "0.9.4" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 43e7be2..623e98d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -49,6 +49,11 @@ dependencies: image_picker: ^1.1.2 csc_picker: ^0.2.7 auto_size_text: ^3.0.0 + firebase_core: ^3.3.0 + firebase_messaging: ^15.0.4 + flutter_local_notifications: ^17.2.1+2 + firebase_crashlytics: ^4.0.4 + firebase_analytics: ^11.2.1 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 779f0ee..9f7d909 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -7,12 +7,15 @@ #include "generated_plugin_registrant.h" #include +#include #include #include void RegisterPlugins(flutter::PluginRegistry* registry) { FileSelectorWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("FileSelectorWindows")); + FirebaseCorePluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FirebaseCorePluginCApi")); SyncfusionPdfviewerWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("SyncfusionPdfviewerWindowsPlugin")); UrlLauncherWindowsRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 3757972..d9d5615 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST file_selector_windows + firebase_core syncfusion_pdfviewer_windows url_launcher_windows )