Skip to content

Commit

Permalink
Merge commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Thesmader committed Apr 25, 2020
2 parents 0da8a98 + 696b354 commit b5cdc73
Show file tree
Hide file tree
Showing 19 changed files with 509 additions and 58 deletions.
Binary file added gogrocy/assets/images/cart_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions gogrocy/lib/core/models/cart_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class cart_list {
List<Cart> cart;
int sum;

cart_list({this.cart, this.sum});

factory cart_list.fromJson(Map<String, dynamic> json) {
return cart_list(
cart: json['cart'] != null ? (json['cart'] as List).map((i) => Cart.fromJson(i)).toList() : null,
sum: json['sum'],
);
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['sum'] = this.sum;
if (this.cart != null) {
data['cart'] = this.cart.map((v) => v.toJson()).toList();
}
return data;
}
}
class Cart {
String cart_id;
String category;
String date;
String description;
String id;
String image;
String name;
String price;
String product_id;
String quantity;
String quantity_ordered;
String unit;
String user_id;

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});

factory Cart.fromJson(Map<String, dynamic> json) {
return Cart(
cart_id: json['cart_id'],
category: json['category'],
date: json['date'],
description: json['description'],
id: json['id'],
image: json['image'],
name: json['name'],
price: json['price'],
product_id: json['product_id'],
quantity: json['quantity'],
quantity_ordered: json['quantity_ordered'],
unit: json['unit'],
user_id: json['user_id'],
);
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['cart_id'] = this.cart_id;
data['category'] = this.category;
data['date'] = this.date;
data['description'] = this.description;
data['id'] = this.id;
data['image'] = this.image;
data['name'] = this.name;
data['price'] = this.price;
data['product_id'] = this.product_id;
data['quantity'] = this.quantity;
data['quantity_ordered'] = this.quantity_ordered;
data['unit'] = this.unit;
data['user_id'] = this.user_id;
return data;
}
}
21 changes: 19 additions & 2 deletions gogrocy/lib/core/services/api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:gogrocy/core/models/cart_list.dart';
import 'package:gogrocy/core/models/product.dart';
import 'package:gogrocy/core/models/signup_model.dart';
import 'package:gogrocy/core/models/user.dart';
Expand All @@ -10,6 +11,7 @@ import 'package:gogrocy/service_locator.dart';
import 'package:http/http.dart' as http;

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

const String allProducts = baseUrl + "getProducts";
const String singleProduct = baseUrl + "getProduct";
Expand All @@ -18,6 +20,7 @@ const String login = baseUrl + "login";
const String signUp = baseUrl + "signup";
const String verifyUser = baseUrl + "verifyUser";
const String addAddress = baseUrl + "add_address";
const String cartList=baseUrl+'getCartItems';

class Apis {
final SharedPrefsService _sharedPrefsService = locator<SharedPrefsService>();
Expand Down Expand Up @@ -118,7 +121,6 @@ class Apis {
return user;
}
}

Future<List<Product>> getAllProducts() async {
var client = new http.Client();
bool connectionState = await checkStatus();
Expand All @@ -137,6 +139,21 @@ class Apis {
}
}

Future<cart_list> getCartList() async {
var client = new http.Client();
bool connectionState = await checkStatus();
if (connectionState) //TODO: Add a proper else return
{
var response = await client.post(cartList,headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $TOKEN',
});
return cart_list.fromJson(json.decode(response.body));
} else
(print("Network failure"));
}

Future<bool> checkStatus() async {
try {
final result = await InternetAddress.lookup('google.com');
Expand Down
10 changes: 10 additions & 0 deletions gogrocy/lib/core/services/shared_prefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ class SharedPrefsService {
final SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getBool("loggedIn")??false;
}
setCartPrice(String s) async{
final SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString("cart", s);
}

Future<String> getCartPrice() async{
final SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString('cart');
}

}
18 changes: 18 additions & 0 deletions gogrocy/lib/core/viewModels/cart_view_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:gogrocy/core/enums/viewstate.dart';
import 'package:gogrocy/core/models/cart_list.dart';
import 'package:gogrocy/core/services/api.dart';
import 'package:gogrocy/core/viewModels/base_model.dart';
import 'package:gogrocy/service_locator.dart';

class CartViewModel extends BaseModel{
Apis _apis=locator<Apis>();

cart_list cartList;

Future getCartList() async{
setState(ViewState.Busy);
cartList=await _apis.getCartList();
setState(ViewState.Idle);
}

}
2 changes: 2 additions & 0 deletions gogrocy/lib/service_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:gogrocy/core/services/authentication_service.dart';
import 'package:gogrocy/core/services/internet_services.dart';
import 'package:gogrocy/core/services/navigation_service.dart';
import 'package:gogrocy/core/services/shared_prefs.dart';
import 'package:gogrocy/core/viewModels/cart_view_model.dart';
import 'package:gogrocy/core/viewModels/login_model.dart';
import 'package:gogrocy/core/viewModels/startup_view_model.dart';
import 'package:gogrocy/ui/views/signup_view.dart';
Expand All @@ -21,5 +22,6 @@ void setupLocator() {
locator.registerFactory<LoginModel>(() => LoginModel());
locator.registerLazySingleton(()=>Apis());
locator.registerFactory(()=>AllProductsModel());
locator.registerFactory(()=>CartViewModel());
locator.registerFactory(()=>BottomNavBarProvider());
}
13 changes: 13 additions & 0 deletions gogrocy/lib/ui/shared/colors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:flutter/material.dart';

final Color PRIMARY_COLOR=Color(0xff5FD900);
final Color CATEGORY_LIST_BOX=Color.fromRGBO(196, 196, 196, 0.3);

final Color VIEW_ALL_BUTTON_TEXT=Color.fromRGBO(95, 210, 0, 1);
final Color VIEW_ALL_BUTTON_BACKGROUND=Color.fromRGBO(95, 210, 0, 0.15);

final Color CART_HEADER_COLOR=Color(0xff3F4250);
final Color CART_BUTTON_BACKGROUND=Color.fromRGBO(255, 193, 72, 0.2);
final Color CART_BUTTON_TEXT=Color(0xffEA9A00);

final Color CART_COUNTER_BACKGROUND=Color(0xffebebeb);
19 changes: 17 additions & 2 deletions gogrocy/lib/ui/shared/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,28 @@ class HomePageConfig {
static double viewAllButtonHeight = (25.89 / 823) * screenHeight;

static double lookingForPaddingTop = (37 / 823) * screenHeight;
static double lookingForPaddingBottom = (37 / 823) * screenHeight;
static double lookingForPaddingBottom = (20 / 823) * screenHeight;

static double categoryListHeight = (168 / 823) * screenHeight;
static double categoryListWidth = (168 / 411) * screenWidth;
static double categoryBoxHeight = (86 / 823) * screenHeight;
static double categotyBoxWidth = (168 / 411) * screenWidth;
static double categoryBoxWidth = (168 / 411) * screenWidth;
static double categoryImageWidth=(144/411)*screenWidth;
static double categoryImageHeight=(115/823)*screenHeight;

static double productGridWidth = (171 / 823) * screenHeight;
static double productGridHeight = (171 / 411) * screenHeight;
}

class CartConfig {

static double checkoutButtonWidth=(106/411)*screenWidth;
static double checkoutButtonHeight=(28/823)*screenHeight;

static double imageWidth=(155/411)*screenWidth;
static double imageHeight=(147/823)*screenHeight;

static double counterHeight=(25.46/823)*screenHeight;
static double counterWidth=(91/411)*screenWidth;

}
17 changes: 17 additions & 0 deletions gogrocy/lib/ui/views/cart/cart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'package:gogrocy/ui/views/cart/cart_header.dart';
import 'package:gogrocy/ui/views/cart/cart_list.dart';

class Cart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: <Widget>[
CartHeader(),
CartList()
],
),
);
}
}
71 changes: 71 additions & 0 deletions gogrocy/lib/ui/views/cart/cart_header.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:gogrocy/ui/shared/colors.dart' as colors;
import 'package:gogrocy/ui/shared/constants.dart' as constants;

class CartHeader extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
Image(image: AssetImage('assets/images/cart_background.png')),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
IntrinsicHeight(
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 20.0,
color: colors.CART_HEADER_COLOR,
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text("Your Cart",
style: TextStyle(fontFamily: 'Gilroy',fontSize: 32.0,fontWeight: FontWeight.bold, color: colors.CART_HEADER_COLOR),),
Text("Grand Total",
style: TextStyle(fontFamily: 'Gilroy',fontSize: 14.0,fontWeight: FontWeight.w600, color: colors.CART_HEADER_COLOR),),

],
),
)
],
),
),
),
Padding(
padding: const EdgeInsets.only(left: 28.0,top: 12),
child: RawMaterialButton(
elevation: 0.0,
onPressed: () {},
fillColor: colors.CART_BUTTON_BACKGROUND,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(3),
),
child: SizedBox(
width: constants.CartConfig.checkoutButtonWidth,
height: constants.CartConfig.checkoutButtonHeight,
child: Center(
child: Text(
'Checkout Now',
style: TextStyle(
color: colors.CART_BUTTON_TEXT,
fontSize: 13.0,
fontWeight: FontWeight.bold),
),
),
),
),
)
],
)
],
);
}
}
Loading

0 comments on commit b5cdc73

Please sign in to comment.