UI
Files
1. main.dart
import 'package:b/Provider/add_to_cart_provider.dart';
import 'package:b/Provider/favorite_provider.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'screens/nav_bar_screen.dart';
import 'package:provider/provider.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) => MultiProvider(
providers: [
// for add to cart
ChangeNotifierProvider(create: (_)=>CartProvider()),
// for favorite
ChangeNotifierProvider(create: (_)=>FavoriteProvider()),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
// theme: ThemeData(
// textTheme: GoogleFonts.mulishTextTheme(),
// ),
home: const BottomNavBar(),
),
);
}
2. screens/nav_bar_screen.dart
import 'package:b/constants.dart';
import 'package:b/screens/Cart/cart_screen.dart';
import 'package:b/screens/Home/home_screen.dart';
import 'package:b/screens/Profile/profile.dart';
import 'package:flutter/material.dart';
import 'Favorite/favorite.dart';
class BottomNavBar extends StatefulWidget {
const BottomNavBar({super.key});
@override
State createState() => _BottomNavBarState();
}
class _BottomNavBarState extends State {
int cuttentIndex = 2;
List screens = const [
Scaffold(),
Favorite(),
HomeScreen(),
CartScreen(),
Profile(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
cuttentIndex = 2;
});
},
shape: const CircleBorder(),
backgroundColor: kprimaryColor,
child: const Icon(
Icons.home,
color: Colors.white,
size: 35,
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
elevation: 1,
height: 60,
color: Colors.white,
shape: const CircularNotchedRectangle(),
notchMargin: 10,
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {
setState(() {
cuttentIndex = 0;
});
},
icon: Icon(
Icons.grid_view_outlined,
size: 30,
color: cuttentIndex == 0 ? kprimaryColor : Colors.grey.shade400,
),
),
IconButton(
onPressed: () {
setState(() {
cuttentIndex = 1;
});
},
icon: Icon(
Icons.favorite_border,
size: 30,
color: cuttentIndex == 1 ? kprimaryColor : Colors.grey.shade400,
),
),
const SizedBox(
width: 15,
),
IconButton(
onPressed: () {
setState(() {
cuttentIndex = 3;
});
},
icon: Icon(
Icons.shopping_cart_outlined,
size: 30,
color: cuttentIndex == 3 ? kprimaryColor : Colors.grey.shade400,
),
),
IconButton(
onPressed: () {
setState(() {
cuttentIndex = 4;
});
},
icon: Icon(
Icons.person,
size: 30,
color: cuttentIndex == 4 ? kprimaryColor : Colors.grey.shade400,
),
),
],
),
),
body: screens[cuttentIndex],
);
}
}
3. screens/Home/home_screen.dart
import 'package:b/models/product_model.dart';
import 'package:b/screens/Home/Widget/product_cart.dart';
import 'package:b/screens/Home/Widget/search_bar.dart';
import 'package:flutter/material.dart';
import '../../models/category.dart';
import 'Widget/home_app_bar.dart';
import 'Widget/image_slider.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State createState() => _HomeScreenState();
}
class _HomeScreenState extends State {
int currentSlider = 0;
int selectedIndex = 0;
@override
Widget build(BuildContext context) {
List> selectcategories = [
all,
shoes,
beauty,
womenFashion,
jewelry,
menFashion
];
return Scaffold(
backgroundColor: Colors.white,
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 35),
// for custom appbar
const CustomAppBar(),
const SizedBox(height: 20),
// for search bar
const MySearchBAR(),
const SizedBox(height: 20),
ImageSlider(
currentSlide: currentSlider,
onChange: (value) {
setState(
() {
currentSlider = value;
},
);
},
),
const SizedBox(height: 20),
// for category selection
categoryItems(),
const SizedBox(height: 20),
if (selectedIndex == 0)
const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Special For You",
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.w800,
),
),
Text(
"See all",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 16,
color: Colors.black54,
),
),
],
),
// for shopping items
const SizedBox(height: 10),
GridView.builder(
padding: EdgeInsets.zero,
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.75,
crossAxisSpacing: 20,
mainAxisSpacing: 20),
itemCount: selectcategories[selectedIndex].length,
itemBuilder: (context, index) {
return ProductCard(
product: selectcategories[selectedIndex][index],
);
},
)
],
),
),
),
);
}
SizedBox categoryItems() {
return SizedBox(
height: 130,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: categoriesList.length,
physics: const BouncingScrollPhysics(),
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
setState(() {
selectedIndex = index;
});
},
child: Container(
padding: const EdgeInsets.all(5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: selectedIndex == index
? Colors.blue[200]
: Colors.transparent,
),
child: Column(
children: [
Container(
height: 65,
width: 65,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: AssetImage(categoriesList[index].image),
fit: BoxFit.cover),
),
),
const SizedBox(height: 5),
Text(
categoriesList[index].title,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
)
],
),
),
);
},
),
);
}
}
screens/Home/Widget/home_app_bar.dart
import 'package:flutter/material.dart';
import '../../../constants.dart';
class CustomAppBar extends StatelessWidget {
const CustomAppBar({
super.key,
});
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
style: IconButton.styleFrom(
backgroundColor: kcontentColor,
padding: const EdgeInsets.all(15),
),
onPressed: () {},
icon: Image.asset(
"images/icon.png",
height: 20,
),
),
IconButton(
style: IconButton.styleFrom(
backgroundColor: kcontentColor,
padding: const EdgeInsets.all(15),
),
onPressed: () {},
iconSize: 30,
icon: const Icon(Icons.notifications_outlined),
),
],
);
}
}
screens/Home/Widget/image_slider.dart
import 'package:flutter/material.dart';
class ImageSlider extends StatelessWidget {
final Function(int) onChange;
final int currentSlide;
const ImageSlider({
super.key,
required this.currentSlide,
required this.onChange,
});
@override
Widget build(BuildContext context) {
return Stack(
children: [
SizedBox(
height: 220,
width: double.infinity,
child: ClipRRect(
borderRadius: BorderRadius.circular(15),
child: PageView(
scrollDirection: Axis.horizontal,
allowImplicitScrolling: true,
onPageChanged: onChange,
physics: const ClampingScrollPhysics(),
children: [
Image.asset(
"images/slider.jpg",
fit: BoxFit.cover,
),
Image.asset(
"images/image1.png",
fit: BoxFit.cover,
),
Image.asset(
"images/slider3.png",
fit: BoxFit.cover,
)
],
),
),
),
Positioned.fill(
bottom: 10,
child: Align(
alignment: Alignment.bottomCenter,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
5,
(index) => AnimatedContainer(
duration: const Duration(microseconds: 300),
width: currentSlide == index ? 15 : 8,
height: 8,
margin: const EdgeInsets.only(right: 3),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: currentSlide == index
? Colors.black
: Colors.transparent,
border: Border.all(
color: Colors.black,
)),
),
),
),
),
),
],
);
}
}
screens/Home/Widget/product_cart.dart
import 'package:b/Provider/favorite_provider.dart';
import 'package:b/constants.dart';
import 'package:b/models/product_model.dart';
import 'package:b/screens/Detail/detail_screen.dart';
import 'package:flutter/material.dart';
class ProductCard extends StatelessWidget {
final Product product;
const ProductCard({super.key, required this.product});
@override
Widget build(BuildContext context) {
final provider = FavoriteProvider.of(context);
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailScreen(product: product),
),
);
},
child: Stack(
children: [
Container(
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: kcontentColor,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 5),
Center(
child: Hero(
tag: product.image,
child: Image.asset(
product.image,
width: 150,
height: 150,
fit: BoxFit.cover,
),
),
),
const SizedBox(height: 10),
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
product.title,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
"\$${product.price}",
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 17,
),
),
Row(
children: List.generate(
product.colors.length,
(index) => Container(
width: 18,
height: 18,
margin: const EdgeInsets.only(right: 4),
decoration: BoxDecoration(
color: product.colors[index],
shape: BoxShape.circle,
),
),
),
)
],
)
],
),
),
Positioned(
child: Align(
alignment: Alignment.topRight,
child: Container(
height: 40,
width: 40,
decoration: const BoxDecoration(
color: kprimaryColor,
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
bottomLeft: Radius.circular(10),
),
),
child: GestureDetector(
onTap: () {
provider.toggleFavorite(product);
},
child: Icon(
provider.isExist(product)
? Icons.favorite
: Icons.favorite_border,
color: Colors.white,
size: 22,
),
),
),
))
],
),
);
}
}
screens/Home/Widget/search_bar.dart
import 'package:b/constants.dart';
import 'package:flutter/material.dart';
class MySearchBAR extends StatelessWidget {
const MySearchBAR({super.key});
@override
Widget build(BuildContext context) {
return Container(
height: 55,
width: double.infinity,
decoration: BoxDecoration(
color: kcontentColor,
borderRadius: BorderRadius.circular(30),
),
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 5),
child: Row(
children: [
const Icon(
Icons.search,
color: Colors.grey,
size: 30,
),
const SizedBox(width: 10),
const Flexible(
flex: 4,
child: TextField(
decoration: InputDecoration(
hintText: "Search...", border: InputBorder.none),
),
),
Container(
height: 25,
width: 1.5,
color: Colors.grey,
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.tune,
color: Colors.grey,
),
),
],
),
);
}
}
screens/Favorite/favorite.dart
import 'package:b/Provider/favorite_provider.dart';
import 'package:flutter/material.dart';
import '../../constants.dart';
class Favorite extends StatefulWidget {
const Favorite({super.key});
@override
State createState() => _FavoriteState();
}
class _FavoriteState extends State {
@override
Widget build(BuildContext context) {
final provider = FavoriteProvider.of(context);
final finalList = provider.favorites;
return Scaffold(
backgroundColor: kcontentColor,
appBar: AppBar(
backgroundColor: kcontentColor,
title: const Text(
"Favorite",
style: TextStyle(fontWeight: FontWeight.bold),
),
centerTitle: true,
),
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: finalList.length,
itemBuilder: (context, index) {
final favoriteItems = finalList[index];
return Stack(
children: [
Padding(
padding: const EdgeInsets.all(15),
child: Container(
padding: const EdgeInsets.all(10),
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white,
),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(10),
width: 85,
height: 85,
decoration: BoxDecoration(
color: kcontentColor,
borderRadius: BorderRadius.circular(20),
),
child: Image.asset(favoriteItems.image),
),
const SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
favoriteItems.title,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
const SizedBox(height: 5),
Text(
favoriteItems.category,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.grey.shade400,
fontSize: 16,
),
),
const SizedBox(height: 10),
Text(
"\$${favoriteItems.price}",
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
),
),
],
)
],
),
),
),
// for delete button
Positioned(
top: 50,right: 35,
child: GestureDetector(
onTap: () {
finalList.removeAt(index);
setState(() {
});
},
child: const Icon(
Icons.delete,
color: Colors.red,
size: 25,
),
),
),
],
);
}))
],
),
);
}
}
screens/Detail/detail_screen.dart
import 'package:b/constants.dart';
import 'package:b/models/product_model.dart';
import 'package:b/screens/Detail/Widget/addto_cart.dart';
import 'package:b/screens/Detail/Widget/description.dart';
import 'package:b/screens/Detail/Widget/detail_app_bar.dart';
import 'package:b/screens/Detail/Widget/image_slider.dart';
import 'package:b/screens/Detail/Widget/items_details.dart';
import 'package:flutter/material.dart';
class DetailScreen extends StatefulWidget {
final Product product;
const DetailScreen({super.key, required this.product});
@override
State createState() => _DetailScreenState();
}
class _DetailScreenState extends State {
int currentImage = 0;
int currentColor = 1;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: kcontentColor,
// for add to cart , icon and quantity
floatingActionButton: AddToCart(product: widget.product),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
body: SafeArea(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// for back button share and favorite,
DetailAppBar(product: widget.product,),
// for detail image slider
MyImageSlider(
image: widget.product.image,
onChange: (index) {
setState(() {
currentImage = index;
});
},
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
5,
(index) => AnimatedContainer(
duration: const Duration(microseconds: 300),
width: currentImage == index ? 15 : 8,
height: 8,
margin: const EdgeInsets.only(right: 3),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: currentImage == index
? Colors.black
: Colors.transparent,
border: Border.all(
color: Colors.black,
),
),
),
),
),
const SizedBox(height: 20),
Container(
width: double.infinity,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(40),
topLeft: Radius.circular(40),
),
),
padding: const EdgeInsets.only(
left: 20,
right: 20,
top: 20,
bottom: 100,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// for product name, price, rating, and seller
ItemsDetails(product: widget.product),
const SizedBox(height: 20),
const Text(
"Color",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 22),
),
const SizedBox(height: 20),
Row(
children: List.generate(
widget.product.colors.length,
(index) => GestureDetector(
onTap: () {
setState(() {
currentColor = index;
});
},
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
width: 40,
height: 40,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: currentColor == index
? Colors.white
: widget.product.colors[index],
border: currentColor == index
? Border.all(
color: widget.product.colors[index],
)
: null,
),
padding: currentColor == index
? const EdgeInsets.all(2)
: null,
margin: const EdgeInsets.only(right: 10),
child: Container(
width: 35,
height: 35,
decoration: BoxDecoration(
color: widget.product.colors[index],
shape: BoxShape.circle),
),
),
),
),
),
const SizedBox(height: 25),
// for description
Description(description: widget.product.description,)
],
),
)
],
),
)),
);
}
}
screens/Detail/Widget/addto_cart.dart
import 'package:b/Provider/add_to_cart_provider.dart';
import 'package:b/constants.dart';
import 'package:b/models/product_model.dart';
import 'package:flutter/material.dart';
class AddToCart extends StatefulWidget {
final Product product;
const AddToCart({super.key, required this.product});
@override
State createState() => _AddToCartState();
}
class _AddToCartState extends State {
int currentIndex = 1;
@override
Widget build(BuildContext context) {
final provider = CartProvider.of(context);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Container(
height: 85,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.black,
),
padding: const EdgeInsets.symmetric(horizontal: 15),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border: Border.all(color: Colors.white, width: 2),
),
child: Row(
children: [
IconButton(
onPressed: () {
if (currentIndex != 1) {
setState(() {
currentIndex--;
});
}
},
iconSize: 18,
icon: const Icon(
Icons.remove,
color: Colors.white,
),
),
const SizedBox(width: 5),
Text(
currentIndex.toString(),
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
const SizedBox(width: 5),
IconButton(
onPressed: () {
setState(() {
currentIndex++;
});
},
iconSize: 18,
icon: const Icon(
Icons.add,
color: Colors.white,
),
)
],
),
),
GestureDetector(
onTap: () {
provider.toogleFavorite(widget.product);
// if items is add then show this snackbar
const snackBar = SnackBar(
content: Text(
"Successfully added!",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25,
color: Colors.white,
),
),
duration: Duration(seconds: 1),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
},
child: Container(
height: 55,
decoration: BoxDecoration(
color: kprimaryColor,
borderRadius: BorderRadius.circular(50),
),
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(horizontal: 50),
child: const Text(
"Add to Cart",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20),
),
),
)
],
),
),
);
}
}
screens/Detail/Widget/description.dart
import 'package:b/constants.dart';
import 'package:flutter/material.dart';
class Description extends StatelessWidget {
final String description;
const Description({super.key, required this.description});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: 120,
height: 40,
decoration: BoxDecoration(
color: kprimaryColor,
borderRadius: BorderRadius.circular(20),
),
alignment: Alignment.center,
child: const Text(
"Description",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 16),
),
),
const Text(
"Specifications",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 16),
),
const Text(
"Reviews",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
],
),
const SizedBox(height: 20),
Text(
description,
style: const TextStyle(
fontSize: 16,
color: Colors.grey,
),
),
],
);
}
}
screens/Detail/Widget/detail_app_bar.dart
import 'package:b/models/product_model.dart';
import 'package:flutter/material.dart';
import '../../../Provider/favorite_provider.dart';
class DetailAppBar extends StatelessWidget {
final Product product;
const DetailAppBar({super.key, required this.product});
@override
Widget build(BuildContext context) {
final provider = FavoriteProvider.of(context);
return Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.white,
padding: const EdgeInsets.all(15),
),
onPressed: () {
Navigator.pop(context);
},
icon: const Icon(Icons.arrow_back_ios),
),
const Spacer(),
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.white,
padding: const EdgeInsets.all(15),
),
onPressed: () {},
icon: const Icon(Icons.share_outlined),
),
const SizedBox(width: 10),
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.white,
padding: const EdgeInsets.all(15),
),
onPressed: () {
provider.toggleFavorite(product);
},
icon: Icon(
provider.isExist(product)
? Icons.favorite
: Icons.favorite_border,
color: Colors.black,
size: 25,
),
),
],
),
);
}
}
screens/Detail/Widget/image_slider.dart
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
class MyImageSlider extends StatelessWidget {
final Function(int) onChange;
final String image;
const MyImageSlider({
super.key,
required this.image,
required this.onChange,
});
@override
Widget build(BuildContext context) {
return SizedBox(
height: 250,
child: PageView.builder(
onPageChanged: onChange,
itemBuilder: (context, index) {
return Hero(
tag: image,
child: Image.asset(image),
);
},
),
);
}
}
screens/Detail/Widget/items_details.dart
import 'package:b/constants.dart';
import 'package:b/models/product_model.dart';
import 'package:flutter/material.dart';
class ItemsDetails extends StatelessWidget {
final Product product;
const ItemsDetails({super.key, required this.product});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
product.title,
style: const TextStyle(
fontWeight: FontWeight.w800,
fontSize: 25,
),
),
Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"\$${product.price}",
style: const TextStyle(
fontWeight: FontWeight.w800,
fontSize: 25,
),
),
const SizedBox(height: 10),
// for rating
Row(
children: [
Container(
width: 55,
height: 25,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: kprimaryColor,
),
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(horizontal: 5),
child: Row(
children: [
const Icon(
Icons.star,
size: 15,
color: Colors.white,
),
const SizedBox(
width: 3,
),
Text(
product.rate.toString(),
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 14,
),
),
],
),
),
const SizedBox(width: 5),
Text(
product.review,
style: const TextStyle(
color: Colors.grey,
fontSize: 15,
),
)
],
)
],
),
const Spacer(),
Text.rich(
TextSpan(
children: [
const TextSpan(
text: "Seller: ",
style: TextStyle(fontSize: 16),
),
TextSpan(
text: product.seller,
style: const TextStyle(
fontSize: 16, fontWeight: FontWeight.bold),
),
],
),
),
],
)
],
);
}
}
screens/Cart/cart_screen.dart
import 'package:b/Provider/add_to_cart_provider.dart';
import 'package:b/screens/Cart/check_out.dart';
import 'package:flutter/material.dart';
import '../../constants.dart';
class CartScreen extends StatefulWidget {
const CartScreen({super.key});
@override
State createState() => _CartScreenState();
}
class _CartScreenState extends State {
@override
Widget build(BuildContext context) {
final provider = CartProvider.of(context);
final finalList = provider.cart;
producrQuantity(IconData icon, int index) {
return GestureDetector(
onTap: () {
setState(() {
icon == Icons.add
? provider.incrementQtn(index)
: provider.decrementQtn(index);
});
},
child: Icon(
icon,
size: 20,
),
);
}
return Scaffold(
backgroundColor: kcontentColor,
bottomSheet: CheckOutBox(),
body: SafeArea(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.white,
padding: const EdgeInsets.all(15),
),
onPressed: () {},
icon: const Icon(
Icons.arrow_back_ios,
),
),
const Text(
"My Cart",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 25,
),
),
const SizedBox()
],
),
),
Expanded(
child: ListView.builder(
shrinkWrap: true,
itemCount: finalList.length,
itemBuilder: (context, index) {
final cartItems = finalList[index];
return Stack(
children: [
Padding(
padding: const EdgeInsets.all(15),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white,
),
padding: const EdgeInsets.all(20),
child: Row(
children: [
Container(
height: 100,
width: 90,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: kcontentColor,
),
// padding: const EdgeInsets.all(20),
child: Image.asset(cartItems.image),
),
const SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
cartItems.title,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
const SizedBox(
height: 5,
),
Text(
cartItems.category,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: Colors.grey.shade400),
),
const SizedBox(height: 10),
Text(
"\$${cartItems.price}",
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
),
),
],
)
],
),
),
),
Positioned(
top: 35,
right: 35,
child: Column(
children: [
// for remove items
IconButton(
onPressed: () {
// for remove ites for cart
finalList.removeAt(index);
setState(() {});
},
icon: const Icon(
Icons.delete,
color: Colors.red,
size: 20,
),
),
// for items quantity
const SizedBox(height: 10),
Container(
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: kcontentColor,
border: Border.all(
color: Colors.grey.shade400,
width: 2,
),
),
child: Row(
children: [
const SizedBox(width: 10),
producrQuantity(Icons.add, index),
const SizedBox(width: 10),
Text(
cartItems.quantity.toString(),
style: const TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
const SizedBox(width: 10),
producrQuantity(Icons.remove, index),
const SizedBox(width: 10),
],
),
)
],
),
),
],
);
},
),
),
],
)),
);
}
}
screens/Cart/check_out.dart
import 'package:b/Provider/add_to_cart_provider.dart';
import 'package:b/constants.dart';
import 'package:flutter/material.dart';
class CheckOutBox extends StatelessWidget {
const CheckOutBox({super.key});
@override
Widget build(BuildContext context) {
final provider = CartProvider.of(context);
return Container(
height: 300,
width: double.infinity,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(30),
bottomLeft: Radius.circular(30),
),
),
padding: const EdgeInsets.all(20),
child: Column(
children: [
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: BorderSide.none,
),
contentPadding: const EdgeInsets.symmetric(
vertical: 5,
horizontal: 15,
),
filled: true,
fillColor: kcontentColor,
hintText: "Enter Discoutn Code",
hintStyle: const TextStyle(
color: Colors.grey,
fontWeight: FontWeight.w600,
fontSize: 14,
),
suffixIcon: TextButton(
onPressed: () {},
child: const Text(
"Apply",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: kprimaryColor,
),
),
),
),
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
"SbuTotal",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.grey,
fontSize: 16,
),
),
Text(
"\$${provider.totalPrice()}",
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
)
],
),
const SizedBox(height: 10),
const Divider(),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
"total",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
Text(
"\$${provider.totalPrice()}",
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
)
],
),
const SizedBox(height: 20),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: kprimaryColor,
minimumSize: const Size(double.infinity, 55),
),
onPressed: () {},
child: const Text(
"Check Out",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Colors.white,
),
))
],
),
);
}
}
// now we add the provider and display the total price
models/category.dart
class Category {
final String title;
final String image;
Category({
required this.title,
required this.image,
});
}
final List categoriesList = [
Category(
title: "All",
image: "images/all.png",
),
Category(
title: "Shoes",
image: "images/shoes.png",
),
Category(
title: "Beauty",
image: "images/beauty.png",
),
Category(
title: "Women's\nFashion",
image: "images/image1.png",
),
Category(
title: "Jewelry",
image: "images/jewelry.png",
),
Category(
title: "Men's\nFashion",
image: "images/men.png",
),
];
models/product_model.dart
import 'package:flutter/material.dart';
class Product {
final String title;
final String description;
final String image;
final String review;
final String seller;
final double price;
final List colors;
final String category;
final double rate;
int quantity;
Product(
{required this.title,
required this.review,
required this.description,
required this.image,
required this.price,
required this.colors,
required this.seller,
required this.category,
required this.rate,
required this.quantity});
}
final List all = [
Product(
title: "Wireless Headphones",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/all/wireless.png",
price: 120,
seller: "Tariqul isalm",
colors: [
Colors.black,
Colors.blue,
Colors.orange,
],
category: "Electronics",
review: "(320 Reviews)",
rate: 4.8,
quantity: 1,
),
Product(
title: "Woman Sweter",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/all/sweet.png",
price: 120,
seller: "Joy Store",
colors: [
Colors.brown,
Colors.deepPurple,
Colors.pink,
],
category: "Woman Fashion",
review: "(32 Reviews)",
rate: 4.5,
quantity: 1,
),
Product(
title: "Smart Watch",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/all/miband.jpg",
price: 55,
seller: "Ram Das",
colors: [
Colors.black,
Colors.amber,
Colors.purple,
],
category: "Electronics",
review: "(20 Reviews)",
rate: 4.0,
quantity: 1,
),
Product(
title: "Mens Jacket",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/all/jacket.png",
price: 155,
seller: "Jacket Store",
colors: [
Colors.blueAccent,
Colors.orange,
Colors.green,
],
category: "Men Fashion",
review: "(20 Reviews)",
rate: 5.0,
quantity: 1,
),
Product(
title: "Watch",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/men fashion/watch.png",
price: 1000,
seller: "Jacket Store",
colors: [
Colors.lightBlue,
Colors.orange,
Colors.purple,
],
category: "MenFashion",
review: "(100 Reviews)",
rate: 5.0,
quantity: 1,
),
Product(
title: "Air Jordan",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/shoes/Air Jordan.png",
price: 255,
seller: "The Seller",
colors: [
Colors.grey,
Colors.amber,
Colors.purple,
],
category: "Shoes",
review: "(55 Reviews)",
rate: 5.0,
quantity: 1,
),
Product(
title: "Super Perfume",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/beauty/perfume.png",
price: 155,
seller: "Love Seller",
colors: [
Colors.purpleAccent,
Colors.pinkAccent,
Colors.green,
],
category: "Beauty",
review: "(99 Reviews)",
rate: 4.7,
quantity: 1,
),
Product(
title: "Wedding Ring",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/jewelry/wedding ring.png",
price: 155,
seller: "I Am Seller",
colors: [
Colors.brown,
Colors.purpleAccent,
Colors.blueGrey,
],
category: "Jewelry",
review: "(80 Reviews)",
rate: 4.5,
quantity: 1,
),
Product(
title: " Pants",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/women fashion/pants.png",
price: 155,
seller: "PK Store",
colors: [
Colors.lightGreen,
Colors.blueGrey,
Colors.deepPurple,
],
category: "WomenFashion",
review: "(55 Reviews)",
rate: 5.0,
quantity: 1,
),
];
final List shoes = [
Product(
title: "Air Jordan",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/shoes/Air Jordan.png",
price: 255,
seller: "The Seller",
colors: [
Colors.grey,
Colors.amber,
Colors.purple,
],
category: "Shoes",
review: "(55 Reviews)",
rate: 5.0,
quantity: 1,
),
Product(
title: "Vans Old Skool",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/shoes/vans old skool.png",
price: 300,
seller: "Mrs Store",
colors: [
Colors.blueAccent,
Colors.blueGrey,
Colors.green,
],
category: "Shoes",
review: "(200 Reviews)",
rate: 5.0,
quantity: 1,
),
Product(
title: "Women-Shoes",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/shoes/women-shoes.png",
price: 500,
seller: "Shoes Store",
colors: [
Colors.red,
Colors.orange,
Colors.greenAccent,
],
category: "Shoes",
review: "(100 Reviews)",
rate: 4.8,
quantity: 1,
),
Product(
title: "Sports Shoes",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/shoes/sports shoes.png",
price: 155,
seller: "Hari Store",
colors: [
Colors.deepPurpleAccent,
Colors.orange,
Colors.green,
],
category: "Shoes",
review: "(60 Reviews)",
rate: 3.0,
quantity: 1,
),
Product(
title: "White Sneaker",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/shoes/white sneaker.png",
price: 1000,
seller: "Jacket Store",
colors: [
Colors.blueAccent,
Colors.orange,
Colors.green,
],
category: "Shoes",
review: "(00 Reviews)",
rate: 0.0,
quantity: 1,
),
];
final List beauty = [
Product(
title: "Face Care Product",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/beauty/face care.png",
price: 1500,
seller: "Yojana Seller",
colors: [
Colors.pink,
Colors.amber,
Colors.deepOrangeAccent,
],
category: "Beauty",
review: "(200 Reviews)",
rate: 4.0,
quantity: 1,
),
Product(
title: "Super Perfume",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/beauty/perfume.png",
price: 155,
seller: "Love Seller",
colors: [
Colors.purpleAccent,
Colors.pinkAccent,
Colors.green,
],
category: "Beauty",
review: "(99 Reviews)",
rate: 4.7,
quantity: 1,
),
Product(
title: "Skin-Care Product",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/beauty/skin-care.png",
price: 999,
seller: "Mr Beast",
colors: [
Colors.black12,
Colors.orange,
Colors.white38,
],
category: "Beauty",
review: "(20 Reviews)",
rate: 4.2,
quantity: 1,
),
];
final List womenFashion = [
Product(
title: " Women Kurta",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/women fashion/kurta.png",
price: 299,
seller: "Sila Store",
colors: [
Colors.grey,
Colors.black54,
Colors.purple,
],
category: "WomenFashion",
review: "(25 Reviews)",
rate: 5.0,
quantity: 1,
),
Product(
title: "Mens Jacket",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/women fashion/lehenga.png",
price: 666,
seller: "My Store",
colors: [
Colors.black,
Colors.orange,
Colors.green,
],
category: "WomenFashion",
review: "(100 Reviews)",
rate: 4.0,
quantity: 1,
),
Product(
title: "T-Shert",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/women fashion/t-shert.png",
price: 155,
seller: "Love Store",
colors: [
Colors.blueAccent,
Colors.redAccent,
Colors.deepOrangeAccent,
],
category: "Electronics",
review: "(20 Reviews)",
rate: 5.0,
quantity: 1,
),
Product(
title: " Pants",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/women fashion/pants.png",
price: 155,
seller: "PK Store",
colors: [
Colors.lightGreen,
Colors.blueGrey,
Colors.deepPurple,
],
category: "WomenFashion",
review: "(55 Reviews)",
rate: 5.0,
quantity: 1,
),
];
final List jewelry = [
Product(
title: "Earrings",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/jewelry/earrings.png",
price: 3000,
seller: "Gold Store",
colors: [
Colors.amber,
Colors.deepPurple,
Colors.pink,
],
category: "Jewelry",
review: "(320 Reviews)",
rate: 4.5,
quantity: 1,
),
Product(
title: "Jewelry-Box",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/jewelry/jewelry-box.png",
price: 300,
seller: "Love Love",
colors: [
Colors.pink,
Colors.orange,
Colors.redAccent,
],
category: "Jewelry",
review: "(100 Reviews)",
rate: 5.0,
quantity: 1,
),
Product(
title: "Wedding Ring",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/jewelry/wedding ring.png",
price: 155,
seller: "I Am Seller",
colors: [
Colors.brown,
Colors.purpleAccent,
Colors.blueGrey,
],
category: "Jewelry",
review: "(80 Reviews)",
rate: 4.5,
quantity: 1,
),
Product(
title: "Necklace-Jewellery",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/jewelry/necklace-jewellery.png",
price: 5000,
seller: "Jewellery Store",
colors: [
Colors.blueAccent,
Colors.orange,
Colors.green,
],
category: "Jewellery",
review: "(22 Reviews)",
rate: 3.5,
quantity: 1,
),
];
final List menFashion = [
Product(
title: "Man Jacket",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/men fashion/man jacket.png",
price: 500,
seller: "Men Store",
colors: [
Colors.brown,
Colors.orange,
Colors.blueGrey,
],
category: "MenFashion",
review: "(90 Reviews)",
rate: 5.0,
quantity: 1,
),
Product(
title: "Men Pants",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/men fashion/pants.png",
price: 400,
seller: "My Store",
colors: [
Colors.black54,
Colors.orange,
Colors.green,
],
category: "MenFashion",
review: "(500 Reviews)",
rate: 4.5,
quantity: 1,
),
Product(
title: "Men Shert",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/men fashion/shert.png",
price: 300,
seller: "Roman Store",
colors: [
Colors.pink,
Colors.amber,
Colors.green,
],
category: "menFashion",
review: "(200 Reviews)",
rate: 3.0,
quantity: 1,
),
Product(
title: "T-Shirt",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/men fashion/t-shirt.png",
price: 200,
seller: "Hot Store",
colors: [
Colors.brown,
Colors.orange,
Colors.blue,
],
category: "MenFashion",
review: "(1k Reviews)",
rate: 5.0,
quantity: 1,
),
Product(
title: "Watch",
description:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Donec massa sapien faucibus et molestie ac feugiat. In massa tempor nec feugiat nisl. Libero id faucibus nisl tincidunt.",
image: "images/men fashion/watch.png",
price: 1000,
seller: "Jacket Store",
colors: [
Colors.lightBlue,
Colors.orange,
Colors.purple,
],
category: "MenFashion",
review: "(100 Reviews)",
rate: 5.0,
quantity: 1,
),
];
Provider/add_to_cart_provider.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/product_model.dart';
class CartProvider extends ChangeNotifier {
final List _cart = [];
List get cart => _cart;
void toogleFavorite(Product product) {
// toogleFavorite is just a name you can give what ever you wants to
if (_cart.contains(product)) {
for (Product element in _cart) {
element.quantity++;
}
} else {
_cart.add(product);
}
notifyListeners();
}
// for increment
incrementQtn(int index) {
_cart[index].quantity++;
notifyListeners();
}
// for decrement
decrementQtn(int index) {
if (_cart[index].quantity <= 1) {
return;
}
_cart[index].quantity--;
notifyListeners();
}
// for total amount
totalPrice() {
double myTotal = 0.0; // initial
for (Product element in _cart) {
myTotal += element.price * element.quantity;
}
return myTotal;
}
static CartProvider of(BuildContext context, {bool listen = true}) {
return Provider.of(
context,
listen: listen,
);
}
}
Provider/favorite_provider.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/product_model.dart';
class FavoriteProvider extends ChangeNotifier {
final List _favorite = [];
List get favorites => _favorite;
void toggleFavorite(Product product) {
if (_favorite.contains(product)) {
_favorite.remove(product);
} else {
_favorite.add(product);
}
notifyListeners();
}
bool isExist(Product product) {
final isExist = _favorite.contains(product);
return isExist;
}
static FavoriteProvider of(BuildContext context, {bool listen = true}) {
return Provider.of(
context,
listen: listen,
);
}
}
pubspec.yaml
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
assets:
- images/
- images/all/
- images/shoes/
- images/beauty/
- images/women fashion/
- images/men fashion/
- images/jewelry/