Skip to content

Commit b5cdc73

Browse files
committed
Merge commit
2 parents 0da8a98 + 696b354 commit b5cdc73

19 files changed

+509
-58
lines changed
5.41 KB
Loading
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
class cart_list {
2+
List<Cart> cart;
3+
int sum;
4+
5+
cart_list({this.cart, this.sum});
6+
7+
factory cart_list.fromJson(Map<String, dynamic> json) {
8+
return cart_list(
9+
cart: json['cart'] != null ? (json['cart'] as List).map((i) => Cart.fromJson(i)).toList() : null,
10+
sum: json['sum'],
11+
);
12+
}
13+
14+
Map<String, dynamic> toJson() {
15+
final Map<String, dynamic> data = new Map<String, dynamic>();
16+
data['sum'] = this.sum;
17+
if (this.cart != null) {
18+
data['cart'] = this.cart.map((v) => v.toJson()).toList();
19+
}
20+
return data;
21+
}
22+
}
23+
class Cart {
24+
String cart_id;
25+
String category;
26+
String date;
27+
String description;
28+
String id;
29+
String image;
30+
String name;
31+
String price;
32+
String product_id;
33+
String quantity;
34+
String quantity_ordered;
35+
String unit;
36+
String user_id;
37+
38+
Cart({this.cart_id, this.category, this.date, this.description, this.id, this.image, this.name, this.price, this.product_id, this.quantity, this.quantity_ordered, this.unit, this.user_id});
39+
40+
factory Cart.fromJson(Map<String, dynamic> json) {
41+
return Cart(
42+
cart_id: json['cart_id'],
43+
category: json['category'],
44+
date: json['date'],
45+
description: json['description'],
46+
id: json['id'],
47+
image: json['image'],
48+
name: json['name'],
49+
price: json['price'],
50+
product_id: json['product_id'],
51+
quantity: json['quantity'],
52+
quantity_ordered: json['quantity_ordered'],
53+
unit: json['unit'],
54+
user_id: json['user_id'],
55+
);
56+
}
57+
58+
Map<String, dynamic> toJson() {
59+
final Map<String, dynamic> data = new Map<String, dynamic>();
60+
data['cart_id'] = this.cart_id;
61+
data['category'] = this.category;
62+
data['date'] = this.date;
63+
data['description'] = this.description;
64+
data['id'] = this.id;
65+
data['image'] = this.image;
66+
data['name'] = this.name;
67+
data['price'] = this.price;
68+
data['product_id'] = this.product_id;
69+
data['quantity'] = this.quantity;
70+
data['quantity_ordered'] = this.quantity_ordered;
71+
data['unit'] = this.unit;
72+
data['user_id'] = this.user_id;
73+
return data;
74+
}
75+
}

gogrocy/lib/core/services/api.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:convert';
22
import 'dart:io';
3-
import 'package:flutter/cupertino.dart';
3+
import 'package:flutter/material.dart';
4+
import 'package:gogrocy/core/models/cart_list.dart';
45
import 'package:gogrocy/core/models/product.dart';
56
import 'package:gogrocy/core/models/signup_model.dart';
67
import 'package:gogrocy/core/models/user.dart';
@@ -10,6 +11,7 @@ import 'package:gogrocy/service_locator.dart';
1011
import 'package:http/http.dart' as http;
1112

1213
const String baseUrl = "https://gogrocy.in/api/";
14+
const String TOKEN='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpYXQiOjE1ODY5NzYxMjEsImlzcyI6Imh0dHBzOlwvXC9nb2dyb2N5LmluXC8iLCJuYmYiOjE1ODY5NzYxMzEsImRhdGEiOnsidXNlcl9pZCI6Ijg1IiwidXNlcl9yb2xlIjoiMSJ9fQ.3jwji_K1l07ttdUUjn4UJbJfuAbrC0msqk7jeftpSzDR7u2d8RCiGWz3ritX3hQIa0MGUe2fIaidErX-xtTQdA';
1315

1416
const String allProducts = baseUrl + "getProducts";
1517
const String singleProduct = baseUrl + "getProduct";
@@ -18,6 +20,7 @@ const String login = baseUrl + "login";
1820
const String signUp = baseUrl + "signup";
1921
const String verifyUser = baseUrl + "verifyUser";
2022
const String addAddress = baseUrl + "add_address";
23+
const String cartList=baseUrl+'getCartItems';
2124

2225
class Apis {
2326
final SharedPrefsService _sharedPrefsService = locator<SharedPrefsService>();
@@ -118,7 +121,6 @@ class Apis {
118121
return user;
119122
}
120123
}
121-
122124
Future<List<Product>> getAllProducts() async {
123125
var client = new http.Client();
124126
bool connectionState = await checkStatus();
@@ -137,6 +139,21 @@ class Apis {
137139
}
138140
}
139141

142+
Future<cart_list> getCartList() async {
143+
var client = new http.Client();
144+
bool connectionState = await checkStatus();
145+
if (connectionState) //TODO: Add a proper else return
146+
{
147+
var response = await client.post(cartList,headers: {
148+
'Content-Type': 'application/json',
149+
'Accept': 'application/json',
150+
'Authorization': 'Bearer $TOKEN',
151+
});
152+
return cart_list.fromJson(json.decode(response.body));
153+
} else
154+
(print("Network failure"));
155+
}
156+
140157
Future<bool> checkStatus() async {
141158
try {
142159
final result = await InternetAddress.lookup('google.com');

gogrocy/lib/core/services/shared_prefs.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ class SharedPrefsService {
2020
final SharedPreferences prefs = await SharedPreferences.getInstance();
2121
return prefs.getBool("loggedIn")??false;
2222
}
23+
setCartPrice(String s) async{
24+
final SharedPreferences prefs = await SharedPreferences.getInstance();
25+
prefs.setString("cart", s);
26+
}
27+
28+
Future<String> getCartPrice() async{
29+
final SharedPreferences prefs = await SharedPreferences.getInstance();
30+
return prefs.getString('cart');
31+
}
32+
2333
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import 'package:gogrocy/core/enums/viewstate.dart';
2+
import 'package:gogrocy/core/models/cart_list.dart';
3+
import 'package:gogrocy/core/services/api.dart';
4+
import 'package:gogrocy/core/viewModels/base_model.dart';
5+
import 'package:gogrocy/service_locator.dart';
6+
7+
class CartViewModel extends BaseModel{
8+
Apis _apis=locator<Apis>();
9+
10+
cart_list cartList;
11+
12+
Future getCartList() async{
13+
setState(ViewState.Busy);
14+
cartList=await _apis.getCartList();
15+
setState(ViewState.Idle);
16+
}
17+
18+
}

gogrocy/lib/service_locator.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:gogrocy/core/services/authentication_service.dart';
33
import 'package:gogrocy/core/services/internet_services.dart';
44
import 'package:gogrocy/core/services/navigation_service.dart';
55
import 'package:gogrocy/core/services/shared_prefs.dart';
6+
import 'package:gogrocy/core/viewModels/cart_view_model.dart';
67
import 'package:gogrocy/core/viewModels/login_model.dart';
78
import 'package:gogrocy/core/viewModels/startup_view_model.dart';
89
import 'package:gogrocy/ui/views/signup_view.dart';
@@ -21,5 +22,6 @@ void setupLocator() {
2122
locator.registerFactory<LoginModel>(() => LoginModel());
2223
locator.registerLazySingleton(()=>Apis());
2324
locator.registerFactory(()=>AllProductsModel());
25+
locator.registerFactory(()=>CartViewModel());
2426
locator.registerFactory(()=>BottomNavBarProvider());
2527
}

gogrocy/lib/ui/shared/colors.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import 'package:flutter/material.dart';
2+
3+
final Color PRIMARY_COLOR=Color(0xff5FD900);
4+
final Color CATEGORY_LIST_BOX=Color.fromRGBO(196, 196, 196, 0.3);
5+
6+
final Color VIEW_ALL_BUTTON_TEXT=Color.fromRGBO(95, 210, 0, 1);
7+
final Color VIEW_ALL_BUTTON_BACKGROUND=Color.fromRGBO(95, 210, 0, 0.15);
8+
9+
final Color CART_HEADER_COLOR=Color(0xff3F4250);
10+
final Color CART_BUTTON_BACKGROUND=Color.fromRGBO(255, 193, 72, 0.2);
11+
final Color CART_BUTTON_TEXT=Color(0xffEA9A00);
12+
13+
final Color CART_COUNTER_BACKGROUND=Color(0xffebebeb);

gogrocy/lib/ui/shared/constants.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,28 @@ class HomePageConfig {
5757
static double viewAllButtonHeight = (25.89 / 823) * screenHeight;
5858

5959
static double lookingForPaddingTop = (37 / 823) * screenHeight;
60-
static double lookingForPaddingBottom = (37 / 823) * screenHeight;
60+
static double lookingForPaddingBottom = (20 / 823) * screenHeight;
6161

6262
static double categoryListHeight = (168 / 823) * screenHeight;
6363
static double categoryListWidth = (168 / 411) * screenWidth;
6464
static double categoryBoxHeight = (86 / 823) * screenHeight;
65-
static double categotyBoxWidth = (168 / 411) * screenWidth;
65+
static double categoryBoxWidth = (168 / 411) * screenWidth;
66+
static double categoryImageWidth=(144/411)*screenWidth;
67+
static double categoryImageHeight=(115/823)*screenHeight;
6668

6769
static double productGridWidth = (171 / 823) * screenHeight;
6870
static double productGridHeight = (171 / 411) * screenHeight;
6971
}
72+
73+
class CartConfig {
74+
75+
static double checkoutButtonWidth=(106/411)*screenWidth;
76+
static double checkoutButtonHeight=(28/823)*screenHeight;
77+
78+
static double imageWidth=(155/411)*screenWidth;
79+
static double imageHeight=(147/823)*screenHeight;
80+
81+
static double counterHeight=(25.46/823)*screenHeight;
82+
static double counterWidth=(91/411)*screenWidth;
83+
84+
}

gogrocy/lib/ui/views/cart/cart.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gogrocy/ui/views/cart/cart_header.dart';
3+
import 'package:gogrocy/ui/views/cart/cart_list.dart';
4+
5+
class Cart extends StatelessWidget {
6+
@override
7+
Widget build(BuildContext context) {
8+
return Scaffold(
9+
body: ListView(
10+
children: <Widget>[
11+
CartHeader(),
12+
CartList()
13+
],
14+
),
15+
);
16+
}
17+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:gogrocy/ui/shared/colors.dart' as colors;
3+
import 'package:gogrocy/ui/shared/constants.dart' as constants;
4+
5+
class CartHeader extends StatelessWidget {
6+
@override
7+
Widget build(BuildContext context) {
8+
return Stack(
9+
children: <Widget>[
10+
Image(image: AssetImage('assets/images/cart_background.png')),
11+
Column(
12+
crossAxisAlignment: CrossAxisAlignment.start,
13+
children: <Widget>[
14+
IntrinsicHeight(
15+
child: Padding(
16+
padding: const EdgeInsets.only(top: 8.0),
17+
child: Row(
18+
crossAxisAlignment: CrossAxisAlignment.start,
19+
children: <Widget>[
20+
Container(
21+
width: 20.0,
22+
color: colors.CART_HEADER_COLOR,
23+
),
24+
Padding(
25+
padding: const EdgeInsets.only(left: 8.0),
26+
child: Column(
27+
crossAxisAlignment: CrossAxisAlignment.start,
28+
mainAxisSize: MainAxisSize.min,
29+
children: <Widget>[
30+
Text("Your Cart",
31+
style: TextStyle(fontFamily: 'Gilroy',fontSize: 32.0,fontWeight: FontWeight.bold, color: colors.CART_HEADER_COLOR),),
32+
Text("Grand Total",
33+
style: TextStyle(fontFamily: 'Gilroy',fontSize: 14.0,fontWeight: FontWeight.w600, color: colors.CART_HEADER_COLOR),),
34+
35+
],
36+
),
37+
)
38+
],
39+
),
40+
),
41+
),
42+
Padding(
43+
padding: const EdgeInsets.only(left: 28.0,top: 12),
44+
child: RawMaterialButton(
45+
elevation: 0.0,
46+
onPressed: () {},
47+
fillColor: colors.CART_BUTTON_BACKGROUND,
48+
shape: RoundedRectangleBorder(
49+
borderRadius: BorderRadius.circular(3),
50+
),
51+
child: SizedBox(
52+
width: constants.CartConfig.checkoutButtonWidth,
53+
height: constants.CartConfig.checkoutButtonHeight,
54+
child: Center(
55+
child: Text(
56+
'Checkout Now',
57+
style: TextStyle(
58+
color: colors.CART_BUTTON_TEXT,
59+
fontSize: 13.0,
60+
fontWeight: FontWeight.bold),
61+
),
62+
),
63+
),
64+
),
65+
)
66+
],
67+
)
68+
],
69+
);
70+
}
71+
}

0 commit comments

Comments
 (0)