Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: "a14f74ff3a1cbd521163c5f03d68113d50af93d3"
revision: "80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819"
channel: "stable"

project_type: app
Expand All @@ -13,11 +13,26 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
- platform: android
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
- platform: ios
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
- platform: linux
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
- platform: macos
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
- platform: web
create_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
base_revision: a14f74ff3a1cbd521163c5f03d68113d50af93d3
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
- platform: windows
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819

# User provided section

Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"java.compile.nullAnalysis.mode": "automatic",
"java.configuration.updateBuildConfiguration": "interactive"
"java.configuration.updateBuildConfiguration": "interactive",
"cmake.sourceDirectory": "D:/Sahil/flutter-apps/Sharekhan/get_flutter_fire/windows/flutter"
}
46 changes: 46 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"project_info": {
"project_number": "784525273637",
"project_id": "sharekhan-project",
"storage_bucket": "sharekhan-project.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:784525273637:android:c1966d53b8f4eb96626dcc",
"android_client_info": {
"package_name": "com.example.get_flutter_fire"
}
},
"oauth_client": [
{
"client_id": "784525273637-605r9ms12s7lbjikujvcvb8nsrqbebmr.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCeBbH7YPz08UZsiirSsJQ0mDtFqYezHsQ"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "784525273637-605r9ms12s7lbjikujvcvb8nsrqbebmr.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "784525273637-a5miokt96an7utjtb3dntpaag9ifb9i9.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.example.getFlutterFire"
}
}
]
}
}
}
],
"configuration_version": "1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.get_flutter_fire

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity()
Binary file added assets/icons/images.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icons/sharekhan_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"flutter":{"platforms":{"android":{"default":{"projectId":"sharekhan-project","appId":"1:784525273637:android:c1966d53b8f4eb96626dcc","fileOutput":"android/app/google-services.json"}},"dart":{"lib/firebase_options.dart":{"projectId":"sharekhan-project","configurations":{"android":"1:784525273637:android:c1966d53b8f4eb96626dcc","ios":"1:784525273637:ios:0d855743258edd6e626dcc","macos":"1:784525273637:ios:0d855743258edd6e626dcc","web":"1:784525273637:web:b34a7d2fd4f32969626dcc","windows":"1:784525273637:web:90330fbc8bedc31e626dcc"}}}}}}
6 changes: 3 additions & 3 deletions lib/app/modules/cart/bindings/cart_binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import '../controllers/cart_controller.dart';
class CartBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<CartController>(
() => CartController(),
);
// Get.lazyPut<CartController>(
// () => CartController(),
// );
}
}
35 changes: 21 additions & 14 deletions lib/app/modules/cart/controllers/cart_controller.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
import 'package:get/get.dart';
import 'package:get_flutter_fire/models/products_admin.dart';

class CartController extends GetxController {
//TODO: Implement CartController
var cartItems = <Product, int>{}.obs; // Map of product to quantity

final count = 0.obs;
@override
void onInit() {
super.onInit();
void addToCart(Product product, int quantity) {
if (cartItems.containsKey(product)) {
cartItems[product] = cartItems[product]! + quantity;
} else {
cartItems[product] = quantity;
}
update();
}

@override
void onReady() {
super.onReady();
void removeFromCart(Product product) {
if (cartItems.containsKey(product)) {
if (cartItems[product]! > 1) {
cartItems[product] = cartItems[product]! - 1; // Decrease quantity
} else {
cartItems.remove(product); // Remove if quantity is 1 or less
}
update();
}
}

@override
void onClose() {
super.onClose();
}

void increment() => count.value++;
double get totalPrice => cartItems.entries
.map((entry) => entry.key.price! * entry.value)
.fold(0, (sum, price) => sum + price);
}
51 changes: 39 additions & 12 deletions lib/app/modules/cart/views/cart_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,47 @@ import '../controllers/cart_controller.dart';

class CartView extends GetView<CartController> {
const CartView({super.key});

@override
Widget build(BuildContext context) {
return ScreenWidget(
appBar: AppBar(
title: Text('${AuthService.to.userName} Cart'),
centerTitle: true,
),
body: const Center(
child: Text(
'CartView is working',
style: TextStyle(fontSize: 20),
return GetBuilder<CartController>(builder: (cartController) {
return Scaffold(
body: Obx(() {
if (cartController.cartItems.isEmpty) {
return const Center(child: Text('No items in cart'));
}
return ListView.builder(
itemCount: cartController.cartItems.length,
itemBuilder: (context, index) {
var product = cartController.cartItems.keys.toList()[index];
var quantity = cartController.cartItems[product]!;
return ListTile(
title: Text(product.name ?? 'Product'),
subtitle: Text('Quantity: $quantity'),
trailing: Text('Rs. ${product.price! * quantity}'),
onTap: () {
// Navigate to product description or allow editing quantity
},
);
},
);
}),
bottomNavigationBar: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Total: Rs. ${cartController.totalPrice}'),
ElevatedButton(
onPressed: () {
// Proceed to payment or checkout
},
child: const Text('Proceed to Payment'),
),
],
),
),
),
screen: screen!,
);
);
});
}
}
121 changes: 103 additions & 18 deletions lib/app/modules/products/controllers/products_controller.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,113 @@
import 'package:get/get.dart';

import '../../../../models/product.dart';
import 'package:get_flutter_fire/models/product_category.dart';
import 'package:get_flutter_fire/models/products_admin.dart';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class ProductsController extends GetxController {
final products = <Product>[].obs;
FirebaseFirestore firestore = FirebaseFirestore.instance;
late CollectionReference prodCollection;
late CollectionReference categoryCollection;

void loadDemoProductsFromSomeWhere() {
products.add(
Product(
name: 'Product added on: ${DateTime.now().toString()}',
id: DateTime.now().millisecondsSinceEpoch.toString(),
),
);
}
List<Product> products = [];
List<Product> productsInUI = [];
List<ProductCategory> categories = [];

// Map to track quantities of each product in the UI
RxMap<Product, int> productQuantities = <Product, int>{}.obs;

@override
void onReady() {
super.onReady();
loadDemoProductsFromSomeWhere();
Future<void> onInit() async {
prodCollection = firestore.collection('products');
categoryCollection = firestore.collection('category');
await fetchCategory();
await fetchProducts();
super.onInit();
}

@override
void onClose() {
Get.printInfo(info: 'Products: onClose');
super.onClose();
// Fetch products from Firestore
fetchProducts() async {
try {
QuerySnapshot productSnapshot = await prodCollection.get();
final List<Product> retrievedProducts = productSnapshot.docs
.map((doc) => Product.fromJson(doc.data() as Map<String, dynamic>))
.toList();
products.clear();
products.assignAll(retrievedProducts);
productsInUI.clear();
productsInUI.assignAll(products);

// Initialize product quantities to 0 for all products
for (var product in products) {
if (!productQuantities.containsKey(product)) {
productQuantities[product] = 0;
}
}
} on Exception catch (e) {
Get.snackbar('Error', e.toString(), colorText: Colors.red);
} finally {
update();
}
}

// Fetch categories from Firestore
fetchCategory() async {
try {
QuerySnapshot categorySnapshot = await categoryCollection.get();
final List<ProductCategory> retrievedCategories = categorySnapshot.docs
.map((doc) =>
ProductCategory.fromJson(doc.data() as Map<String, dynamic>))
.toList();
categories.clear();
categories.assignAll(retrievedCategories);
} on Exception catch (e) {
Get.snackbar('Error', e.toString(), colorText: Colors.red);
} finally {
update();
}
}

// Filter products by category
filterByCategory(String category) {
productsInUI.clear();
productsInUI =
products.where((product) => product.category == category).toList();
update();
}

// Filter products by brand
filterByBrand(List<String> brands) {
if (brands.isEmpty) {
productsInUI = products;
} else {
productsInUI =
products.where((product) => brands.contains(product.brand)).toList();
}
update();
}

// Sort products by price
sortByPrice({required bool ascending}) {
List<Product> sortedProducts = List<Product>.from(productsInUI);
sortedProducts.sort((a, b) => ascending
? a.price!.compareTo(b.price!)
: b.price!.compareTo(a.price!));
productsInUI = sortedProducts;
update();
}

// Increment the quantity of a product
void incrementProductQuantity(Product product) {
productQuantities[product] = (productQuantities[product]!) + 1;
update();
}

// Decrement the quantity of a product
void decrementProductQuantity(Product product) {
final currentQuantity = productQuantities[product]!;
if (currentQuantity > 0) {
productQuantities[product] = currentQuantity - 1;
update();
}
}
}
Loading