Skip to content

Commit d65e922

Browse files
committed
update
1 parent ea1362f commit d65e922

File tree

6 files changed

+58
-14
lines changed

6 files changed

+58
-14
lines changed

final_app/lib/Helper/CartItemWidget.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class _CartItemWidgetState extends State<CartItemWidget> {
5353
Widget build(BuildContext context) {
5454
return Container(
5555
margin: EdgeInsets.all(10),
56-
height: 70,
56+
height: 120,
5757
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 8),
5858
decoration: BoxDecoration(
5959
color: Colors.white,
@@ -109,7 +109,15 @@ class _CartItemWidgetState extends State<CartItemWidget> {
109109
maxLines: 1,
110110
style: GoogleFonts.raleway(
111111
fontSize: 20.0, color: Colors.black
112-
)
112+
),
113+
),
114+
Text(
115+
"Price "+"${widget.cartData.subtotal.toString()}",
116+
overflow: TextOverflow.ellipsis,
117+
maxLines: 1,
118+
style: GoogleFonts.raleway(
119+
fontSize: 20.0, color: Colors.black
120+
),
113121
),
114122
],
115123
),

final_app/lib/api/Details.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ProductDetil{
77
static Future<Detail> getProductbyId(String id) async {
88

99
final response = await http.get(
10-
Uri.encodeFull("https://freshodaily.com/api/product-details/1"),
10+
Uri.encodeFull("https://freshodaily.com/api/product-details/7"),
1111
headers: {"Accept": "application/json"});
1212
var data = jsonDecode(response.body);
1313
print(data);

final_app/lib/api/cart.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class CartApi{
7676
}
7777

7878

79-
8079
static Future<dynamic> deleteCart() async {
8180
final authtoken = await Preferences.getData("authToken");
8281
print("===============================");
@@ -91,4 +90,18 @@ class CartApi{
9190
print(response);
9291
return response;
9392
}
93+
94+
static Future<dynamic> cartCount() async {
95+
final authtoken = await Preferences.getData("authToken");
96+
final response = await http.get(
97+
"https://freshodaily.com/api/cart-count",
98+
headers: <String, String>{
99+
'Accept': 'application/json',
100+
'Authorization': 'Bearer $authtoken',
101+
},
102+
);
103+
var responseJson = jsonDecode(response.body);
104+
var data = responseJson["data"];
105+
return data;
106+
}
94107
}

final_app/lib/pages/MainPage.dart

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:final_app/Helper/SubCategories.dart';
88
import 'package:final_app/Helper/SubCategoriesApi.dart';
99
import 'package:final_app/Helper/TrendingNow.dart';
1010
import 'package:final_app/Helper/TrendingNowApi.dart';
11+
import 'package:final_app/api/cart.dart';
1112
import 'package:final_app/pages/HomePage.dart';
1213
import 'package:final_app/pages/ProfilePage.dart';
1314
import 'package:flutter/services.dart';
@@ -17,6 +18,7 @@ import 'package:final_app/api/loginApi.dart';
1718
import 'package:final_app/models/Categories.dart';
1819
import 'package:flutter/material.dart';
1920
import 'package:google_fonts/google_fonts.dart';
21+
import 'package:badges/badges.dart';
2022
import '../Constants.dart';
2123

2224
import 'package:final_app/Helper/nav_drawer.dart';
@@ -33,18 +35,29 @@ class _MainPageState extends State<MainPage> {
3335
title: Text("Home"),
3436
backgroundColor: Colors.redAccent),
3537
BottomNavigationBarItem(
36-
icon: Icon(Icons.shop), title: Text("Shop"), backgroundColor: Colors.redAccent),
38+
icon: Icon(Icons.shop),
39+
title: Text("Shop"),
40+
backgroundColor: Colors.redAccent),
3741
BottomNavigationBarItem(
3842
icon: Icon(Icons.person),
3943
title: Text("Profile"),
4044
backgroundColor: Colors.redAccent),
4145
];
4246

47+
int count=0;
48+
4349
@override
4450
void initState() {
4551
super.initState();
4652
print("======================== Trending Now Listing ==========");
4753
CategoriesList.TrendingNowListing();
54+
CartApi.cartCount().then((value) {
55+
if (value != 0) {
56+
setState(() {
57+
count = value;
58+
});
59+
}
60+
});
4861
}
4962

5063
int _currentIndex = 0;
@@ -113,13 +126,14 @@ class _MainPageState extends State<MainPage> {
113126
child: CircleAvatar(
114127
backgroundColor: Colors.white,
115128
child: GestureDetector(
116-
onTap: () {
117-
Navigator.of(context).pushNamed('/Cart');
118-
},
119-
child: Icon(
120-
Icons.shopping_cart,
121-
color: Colors.redAccent,
122-
)),
129+
onTap: () {
130+
Navigator.of(context).pushNamed('/Cart');
131+
},
132+
child: Badge(
133+
badgeContent: Text("$count",style: TextStyle(color: Colors.white),),
134+
child: Icon(Icons.shopping_cart),
135+
),
136+
),
123137
),
124138
)
125139
],

final_app/pubspec.lock

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ packages:
2222
url: "https://pub.dartlang.org"
2323
source: hosted
2424
version: "2.4.1"
25+
badges:
26+
dependency: "direct main"
27+
description:
28+
name: badges
29+
url: "https://pub.dartlang.org"
30+
source: hosted
31+
version: "1.1.1"
2532
boolean_selector:
2633
dependency: transitive
2734
description:
@@ -120,14 +127,14 @@ packages:
120127
name: fluttertoast
121128
url: "https://pub.dartlang.org"
122129
source: hosted
123-
version: "7.0.1+1"
130+
version: "7.0.2"
124131
get:
125132
dependency: "direct main"
126133
description:
127134
name: get
128135
url: "https://pub.dartlang.org"
129136
source: hosted
130-
version: "3.4.1"
137+
version: "3.4.2"
131138
global_configuration:
132139
dependency: "direct main"
133140
description:

final_app/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dependencies:
2828
# The following adds the Cupertino Icons font to your application.
2929
# Use with the CupertinoIcons class for iOS style icons.
3030
cupertino_icons: ^0.1.3
31+
badges: ^1.1.1
3132
sk_onboarding_screen: ^1.0.1
3233
splashscreen: ^1.2.0
3334
bottom_indicator_bar: ^1.0.0
@@ -42,6 +43,7 @@ dependencies:
4243
progress_dialog:
4344
fluttertoast: ^7.0.1
4445
get: ^3.4.1
46+
4547
dev_dependencies:
4648
flutter_test:
4749
sdk: flutter

0 commit comments

Comments
 (0)