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
Binary file added assets/images/bagpack.png
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/images/cooking_pan.png
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/images/headphones.png
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/images/kettle.png
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/images/violin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions lib/components/coustom_bottom_nav_bar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:shop_app/screens/favorite/favorite_screen.dart';
import 'package:shop_app/screens/home/home_screen.dart';
import 'package:shop_app/screens/profile/profile_screen.dart';

Expand Down Expand Up @@ -46,11 +47,18 @@ class CustomBottomNavBar extends StatelessWidget {
: inActiveIconColor,
),
onPressed: () =>
Navigator.pushNamed(context, HomeScreen.routeName),
Navigator.of(context).pushNamed(HomeScreen.routeName),
),
IconButton(
icon: SvgPicture.asset("assets/icons/Heart Icon.svg"),
onPressed: () {},
icon: SvgPicture.asset(
"assets/icons/Heart Icon.svg",
color: MenuState.favourite == selectedMenu
? kPrimaryColor
: inActiveIconColor,
),
onPressed: () => Navigator.of(context).pushNamed(
FavoriteScreen.routeName,
),
),
IconButton(
icon: SvgPicture.asset("assets/icons/Chat bubble Icon.svg"),
Expand Down
123 changes: 65 additions & 58 deletions lib/components/product_card.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';
import 'package:shop_app/models/Product.dart';
import 'package:shop_app/screens/details/details_screen.dart';

Expand All @@ -10,15 +11,14 @@ class ProductCard extends StatelessWidget {
const ProductCard({
Key key,
this.width = 140,
this.aspectRetio = 1.02,
@required this.product,
this.aspectRatio = 1.02,
}) : super(key: key);

final double width, aspectRetio;
final Product product;
final double width, aspectRatio;

@override
Widget build(BuildContext context) {
final product = Provider.of<Product>(context);
return Padding(
padding: EdgeInsets.only(left: getProportionateScreenWidth(20)),
child: SizedBox(
Expand All @@ -27,66 +27,73 @@ class ProductCard extends StatelessWidget {
onTap: () => Navigator.pushNamed(
context,
DetailsScreen.routeName,
arguments: ProductDetailsArguments(product: product),
arguments: product,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AspectRatio(
aspectRatio: 1.02,
child: Container(
padding: EdgeInsets.all(getProportionateScreenWidth(20)),
decoration: BoxDecoration(
color: kSecondaryColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(15),
),
child: Hero(
tag: product.id.toString(),
child: Image.asset(product.images[0]),
),
),
),
const SizedBox(height: 10),
Text(
product.title,
style: TextStyle(color: Colors.black),
maxLines: 2,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"\$${product.price}",
style: TextStyle(
fontSize: getProportionateScreenWidth(18),
fontWeight: FontWeight.w600,
color: kPrimaryColor,
child: Container(
height: 230,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
AspectRatio(
aspectRatio: 1.02,
child: Container(
padding: EdgeInsets.all(getProportionateScreenWidth(20)),
decoration: BoxDecoration(
color: kSecondaryColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(15),
),
child: Hero(
tag: product.id.toString(),
child: Image.asset(product.images[0]),
),
),
InkWell(
borderRadius: BorderRadius.circular(50),
onTap: () {},
child: Container(
padding: EdgeInsets.all(getProportionateScreenWidth(8)),
height: getProportionateScreenWidth(28),
width: getProportionateScreenWidth(28),
decoration: BoxDecoration(
color: product.isFavourite
? kPrimaryColor.withOpacity(0.15)
: kSecondaryColor.withOpacity(0.1),
shape: BoxShape.circle,
),
const SizedBox(height: 10),
Text(
product.title,
style: TextStyle(color: Colors.black),
softWrap: true,
overflow: TextOverflow.visible,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"\$${product.price}",
style: TextStyle(
fontSize: getProportionateScreenWidth(18),
fontWeight: FontWeight.w600,
color: kPrimaryColor,
),
child: SvgPicture.asset(
"assets/icons/Heart Icon_2.svg",
color: product.isFavourite
? Color(0xFFFF4848)
: Color(0xFFDBDEE4),
),
InkWell(
borderRadius: BorderRadius.circular(50),
onTap: () {
product.toggleFavoriteStatus();
},
child: Container(
padding: EdgeInsets.all(getProportionateScreenWidth(8)),
height: getProportionateScreenWidth(30),
width: getProportionateScreenWidth(30),
decoration: BoxDecoration(
color: product.isFavorite
? kPrimaryColor.withOpacity(0.15)
: kSecondaryColor.withOpacity(0.1),
shape: BoxShape.circle,
),
child: SvgPicture.asset(
"assets/icons/Heart Icon_2.svg",
color: product.isFavorite
? Color(0xFFFF4848)
: Color(0xFFDBDEE4),
),
),
),
),
],
)
],
],
)
],
),
),
),
),
Expand Down
31 changes: 22 additions & 9 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shop_app/models/Cart.dart';
import 'package:shop_app/routes.dart';
import 'package:shop_app/screens/profile/profile_screen.dart';
import 'package:shop_app/screens/splash/splash_screen.dart';
import 'package:shop_app/theme.dart';

import 'models/Product.dart';

void main() {
runApp(MyApp());
}
Expand All @@ -12,14 +15,24 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: theme(),
// home: SplashScreen(),
// We use routeName so that we dont need to remember the name
initialRoute: SplashScreen.routeName,
routes: routes,
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => Products(),
),
ChangeNotifierProvider(
create: (context) => Cart(),
),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: theme(),
// home: SplashScreen(),
// We use routeName so that we don't need to remember the name
initialRoute: SplashScreen.routeName,
routes: routes,
),
);
}
}
108 changes: 94 additions & 14 deletions lib/models/Cart.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,99 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';

import 'Product.dart';
import 'Product.dart';
class CartItem {
final String id;
final String title;
final double price;
final List<String> images;
int quantity;

class Cart {
final Product product;
final int numOfItem;

Cart({@required this.product, @required this.numOfItem});
CartItem({
@required this.id,
@required this.title,
@required this.price,
@required this.images,
@required this.quantity,
});
}

// Demo data for our cart
class Cart with ChangeNotifier {
Map<String, CartItem> _items = {};

Map<String, CartItem> get items {
return {..._items};
}

int get itemCount {
return _items.length;
}

String get totalAmount {
double total = 0.0;
_items.forEach((key, cartItem) {
total += cartItem.price * cartItem.quantity;
});
return total.toStringAsFixed(2);
}

void addItemToCart(String key, String title, double price, dynamic images) {
_items.putIfAbsent(
key,
() => CartItem(
id: DateTime.now().toString(),
title: title,
price: price,
images: images,
quantity: 1),
);
notifyListeners();
}

List<Cart> demoCarts = [
Cart(product: demoProducts[0], numOfItem: 2),
Cart(product: demoProducts[1], numOfItem: 1),
Cart(product: demoProducts[3], numOfItem: 1),
];
void increaseQuantity(
String key, String title, double price, dynamic images) {
if (_items.containsKey(key)) {
// Change Quantity Only... Add one item to exist product
_items.update(
key,
(oldCartItem) => CartItem(
id: oldCartItem.id,
title: oldCartItem.title,
price: oldCartItem.price,
images: oldCartItem.images,
quantity: oldCartItem.quantity + 1),
);
}
notifyListeners();
}

void decreaseQuantity(
String key, String title, double price, dynamic images) {
if (!_items.containsKey(key)) {
return;
}
// Change Quantity Only... remove one item from exist product
if (_items[key].quantity > 1) {
_items.update(
key,
(oldCartItem) => CartItem(
id: oldCartItem.id,
title: oldCartItem.title,
price: oldCartItem.price,
images: oldCartItem.images,
quantity: oldCartItem.quantity - 1),
);
} else {
_items.remove(key);
}
notifyListeners();
}

void removeItem(String key) {
_items.remove(key);
notifyListeners();
}

void clear() {
_items = {};
notifyListeners();
}
}
Loading