Week 6
Week 6
E-COMMERCE APP
PROVIDER Feature
Product List Screen
Display a list of products with "Add to Cart" buttons
Cart Screen
Show added products, quantity, and total price
Allow users to increment/decrement product quantity or
remove products
Global State Management
Manage the cart state using a CartProvider.
└── models/
│
│ └── product_model.dart
│
│ └── cart_item_model.dart
└── providers/
│
│ └── cart_provider.dart
└── widgets/
│
│ └── product_design.dart
│
│ └── cart_item_card.dart
└── main.dart
class ProductModel {
class CartItemModel {
PROVIDER ProductModel({
int quantity;
required this.id,
CartItemModel({
required this.name,
required this.image,
required this.price,
required this.id,
required this.image,
required this.name,
});
required this.price,
}
this.quantity = 1,
});
//get method
double total = 0;
return total;
incrementQuantity(CartItemModel cartItemModel) {
cartItemModel.quantity++;
notifyListeners();
decrementQuantity(CartItemModel cartItemModel) {
if (cartItemModel.quantity > 1) {
cartItemModel.quantity--;
} else {
notifyListeners();
addToCart(CartItemModel cartItemModel) {
//if there the data doesn’t match the index will be -1”
စ်နေ
} else {
notifyListeners();
clearCart() {
_cartItems.clear();
notifyListeners();
removeFromCart(CartItemModel cartItemModel) {
_cartItems.remove(cartItemModel);
notifyListeners();
point in future. Its used to handle operations that take some time to
&
Example
take time (waiting for the user’s input), and the result will be available
in the future.
FUTURE waiting for user input or making network requests) without blocking
ASYNC
& Example
execution at certain points (like waiting for the user to pick a date or
execution until the result of a Future is available. It’s like telling the
FUTURE
Example
ASYNC
When you call showDatePicker or showTimePicker, you use await to
& pause execution of the code until the user has selected a date or time.
Once the user finishes, the await expression will return the selected
AWAIT value, and execution will continue.
ASYNC
AWAIT
void setTime(TimeOfDay time){
_selectedTime = time;
notifyListeners();}
_selectedDate = date;
notifyListeners();
}}
GovindDev | Flutter Dev | Kan Myint Htun
Date_Time_Picker (Functions)
Future<void> _pickTime(BuildContext context) async {
context: context,
initialTime: TimeOfDay.now(),
FUTURE );
context.read<DateTimeProvider>().setTime(selectedTime!);
ASYNC
}
&
Future<void> _pickDate(BuildContext context) async {
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2000),
lastDate: DateTime(2030),
);
context.read<DateTimeProvider>().setDate(selectedDate!);
context: context,
initialTime: TimeOfDay.now(),
FUTURE );
context.read<DateTimeProvider>().setTime(selectedTime!);
ASYNC
}
&
Future<void> _pickDate(BuildContext context) async {
context: context,
initialDate: DateTime.now(),
firstDate: DateTime(2000),
lastDate: DateTime(2030),
);
context.read<DateTimeProvider>().setDate(selectedDate!);
tag: ‘tag_line’,
child: Widget(),
),
FUTURE
ASYNC
FadeIn
&
FadeIn(
),
....