Skip to content

Commit 8a14512

Browse files
committed
initial commit
0 parents  commit 8a14512

File tree

7 files changed

+215
-0
lines changed

7 files changed

+215
-0
lines changed

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
build/

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: Add your license here.

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# FlutterCart: Your Mobile Shopping Companion
2+
3+
FlutterCart is a versatile Flutter package that brings robust shopping cart capabilities to your mobile application. It leverages Hive for local storage, ensuring your shopping cart data is retained across different app sessions.
4+
5+
## Key Features
6+
7+
- **Initialization**: Kickstart the shopping cart with the `init()` method.
8+
- **Cart Operations**: Include items to the cart with `addToCart`, and remove them using `removeFromCart`.
9+
- **Quantity Control**: Fine-tune the item quantity with `incrementCartItemQuantity` and `decrementCartItemQuantity`.
10+
- **Total Price Calculation**: Fetch the total price of cart items using `calculateTotalPrice`.
11+
- **Item Count**: Retrieve the total number of items with `getCartItemCount`.
12+
- **Cart Clearance**: Wipe out all items from the cart with `clearCart`.
13+
- **Cart Item Display**: Visualize the cart items with `showCartItems`, offering customizable widgets for individual cart items and an empty cart message.
14+
- **Item Count Widget**: Display a widget featuring the current cart item count using `showCartItemCountWidget`.
15+
- **Total Amount Widget**: Showcase a widget revealing the total amount of items in the cart with `showTotalAmountWidget`.
16+
- **Dynamic Cart Item Widget**: Illustrate a widget that updates based on whether a product is in the cart or not, using `showAndUpdateCartItemWidget`.
17+
- **Cart Data Retrieval**: Use `getCartData` in the `FlutterCart` class to fetch a list of cart items and the total price.
18+
19+
## How to Get Started
20+
21+
1. Incorporate the package in your Dart file:
22+
23+
```dart
24+
import 'package:flutter_cart/flutter_cart.dart';
25+
```
26+
27+
2. Set the ball rolling by initializing the cart:
28+
29+
```dart
30+
await FlutterCart().init();
31+
```
32+
33+
3. You're all set to harness the shopping cart features in your application!
34+
35+
## Usage Examples
36+
37+
```dart
38+
// Add products to the cart
39+
await FlutterCart().addToCart(FlutterCartItem());
40+
41+
// Eliminate a product from the cart
42+
await FlutterCart().removeFromCart(productId);
43+
44+
// Increase the product quantity in the cart
45+
await FlutterCart().incrementCartItemQuantity(productId);
46+
47+
// Reduce the product quantity in the cart
48+
await FlutterCart().decrementCartItemQuantity(productId);
49+
50+
// Fetch the total price of cart items
51+
double totalPrice = FlutterCart().calculateTotalPrice();
52+
53+
// Get the total quantity of cart items
54+
int itemCount = FlutterCart().getCartItemCount();
55+
56+
// Empty the cart
57+
FlutterCart().clearCart();
58+
59+
// Fetch cart data and total price
60+
Map<String, dynamic> cartData = FlutterCart().getCartData();
61+
List<FlutterCartItem> cartItems = cartData['cartItems'];
62+
double totalPriceFromData = cartData['totalPrice'];
63+
```
64+
65+
## Widgets
66+
67+
### Cart Item Display
68+
69+
```dart
70+
FlutterCart().showCartItems(
71+
cartTileWidget: ({required FlutterCartItem data}) {
72+
// Your personalized cart item widget
73+
},
74+
showEmptyCartMsgWidget: YourEmptyCartMessageWidget(),
75+
);
76+
```
77+
78+
### Cart Item Count Widget
79+
80+
```dart
81+
FlutterCart().showCartItemCountWidget(
82+
cartItemCountWidgetBuilder: (int itemCount) {
83+
// Your personalized widget displaying the cart item count
84+
},
85+
);
86+
```
87+
88+
### Total Amount Widget
89+
90+
```dart
91+
FlutterCart().showTotalAmountWidget(
92+
cartTotalAmountWidgetBuilder: (double totalAmount) {
93+
// Your personalized widget displaying the total amount
94+
},
95+
);
96+
```
97+
98+
### Dynamic Cart Item Widget
99+
100+
```dart
101+
FlutterCart().showAndUpdateCartItemWidget(
102+
inCartWidget: YourInCartWidget(),
103+
notInCartWidget: YourNotInCartWidget(),
104+
product: yourProduct,
105+
);
106+
```
107+
108+
"Simplify your mobile shopping experience with FlutterCart!"

analysis_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options

lib/flutter_cart.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
library flutter_cart;
2+
3+
/// A Calculator.
4+
class Calculator {
5+
/// Returns [value] plus 1.
6+
int addOne(int value) => value + 1;
7+
}

pubspec.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: flutter_cart
2+
description: "A new Flutter package project."
3+
version: 0.0.1
4+
homepage:
5+
6+
environment:
7+
sdk: '>=3.2.3 <4.0.0'
8+
flutter: ">=1.17.0"
9+
10+
dependencies:
11+
flutter:
12+
sdk: flutter
13+
14+
dev_dependencies:
15+
flutter_test:
16+
sdk: flutter
17+
flutter_lints: ^2.0.0
18+
19+
# For information on the generic Dart part of this file, see the
20+
# following page: https://dart.dev/tools/pub/pubspec
21+
22+
# The following section is specific to Flutter packages.
23+
flutter:
24+
25+
# To add assets to your package, add an assets section, like this:
26+
# assets:
27+
# - images/a_dot_burr.jpeg
28+
# - images/a_dot_ham.jpeg
29+
#
30+
# For details regarding assets in packages, see
31+
# https://flutter.dev/assets-and-images/#from-packages
32+
#
33+
# An image asset can refer to one or more resolution-specific "variants", see
34+
# https://flutter.dev/assets-and-images/#resolution-aware
35+
36+
# To add custom fonts to your package, add a fonts section here,
37+
# in this "flutter" section. Each entry in this list should have a
38+
# "family" key with the font family name, and a "fonts" key with a
39+
# list giving the asset and other descriptors for the font. For
40+
# example:
41+
# fonts:
42+
# - family: Schyler
43+
# fonts:
44+
# - asset: fonts/Schyler-Regular.ttf
45+
# - asset: fonts/Schyler-Italic.ttf
46+
# style: italic
47+
# - family: Trajan Pro
48+
# fonts:
49+
# - asset: fonts/TrajanPro.ttf
50+
# - asset: fonts/TrajanPro_Bold.ttf
51+
# weight: 700
52+
#
53+
# For details regarding fonts in packages, see
54+
# https://flutter.dev/custom-fonts/#from-packages

test/flutter_cart_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
3+
import 'package:flutter_cart/flutter_cart.dart';
4+
5+
void main() {
6+
test('adds one to input values', () {
7+
final calculator = Calculator();
8+
expect(calculator.addOne(2), 3);
9+
expect(calculator.addOne(-7), -6);
10+
expect(calculator.addOne(0), 1);
11+
});
12+
}

0 commit comments

Comments
 (0)