Skip to content

Commit

Permalink
Merge pull request #99 from Onestop-Agrotech/0.5.2
Browse files Browse the repository at this point in the history
[0.5.2+3] beta version
  • Loading branch information
Rahul-Vijay authored Oct 25, 2020
2 parents 983a8ee + 78528a2 commit 551b531
Show file tree
Hide file tree
Showing 20 changed files with 576 additions and 478 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- run: flutter format --set-exit-if-changed .

# Run widget tests for our flutter project.
# - run: flutter test
- run: flutter test

# # Build apk.
# - run: flutter build apk
Expand Down
38 changes: 13 additions & 25 deletions lib/bloc/productsapi_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,19 @@ class ProductsapiBloc extends Bloc<ProductsapiEvent, ProductsapiState> {
Stream<ProductsapiState> mapEventToState(
ProductsapiEvent event,
) async* {
if (event is GetVegetables) {
yield* _loadProducts(_productRepository.fetchVegetables);
} else if (event is GetFruits) {
yield* _loadProducts(_productRepository.fetchFruits);
} else if (event is GetDailyEssentials) {
yield* _loadProducts(_productRepository.fetchDailyEssentials);
if (event is GetProducts) {
try {
yield ProductsapiLoading();
final products = await _productRepository.fetchProducts(event.type);
yield ProductsapiLoaded(products);
} on UnauthorisedException {
yield ProductsapiLoading();
await _productRepository.refreshToken();
final products = await _productRepository.fetchProducts(event.type);
yield ProductsapiLoaded(products);
} catch (err) {
yield ProductsapiError(err.toString());
}
}
}

Stream<ProductsapiState> _loadProducts(func) async* {
try {
yield ProductsapiLoading();
final products = await func();
yield ProductsapiLoaded(products);
} on UnauthorisedException {
yield* _exceptionHandler(func);
} catch (err) {
yield ProductsapiError(err.toString());
}
}

Stream<ProductsapiState> _exceptionHandler(func) async* {
yield ProductsapiLoading();
await _productRepository.refreshToken();
final products = await func();
yield ProductsapiLoaded(products);
}
}
9 changes: 4 additions & 5 deletions lib/bloc/productsapi_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ part of 'productsapi_bloc.dart';
@immutable
abstract class ProductsapiEvent {}

class GetVegetables extends ProductsapiEvent {}

class GetFruits extends ProductsapiEvent {}

class GetDailyEssentials extends ProductsapiEvent {}
class GetProducts extends ProductsapiEvent {
final String type;
GetProducts({@required this.type}) : assert(type != null);
}
2 changes: 1 addition & 1 deletion lib/domain/bestsellers_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BestSellerRepositoryImpl implements BestSellerRepository {
var responseJson = await _returnResponse(response);
return responseJson;
} on SocketException {
throw FetchDataException('No Internet connection');
throw FetchDataException('No Internet Connection!');
}
}

Expand Down
25 changes: 5 additions & 20 deletions lib/domain/product_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import 'package:mvp/models/storeProducts.dart';
import 'package:http/http.dart' as http;

abstract class ProductRepository {
Future<List<StoreProduct>> fetchVegetables();
Future<List<StoreProduct>> fetchFruits();
Future<List<StoreProduct>> fetchDailyEssentials();
Future<List<StoreProduct>> fetchProducts(String type);
}

class ProductRepositoryImpl implements ProductRepository {
Future _fetch(String type) async {
@override
Future<List<StoreProduct>> fetchProducts(type) async {
final SPBox spBox = await SPBox.getSPBoxInstance();
final List<StoreProduct> sp = spBox.getFromSPBox(type);
if (sp.length == 0) {
Expand All @@ -35,21 +34,7 @@ class ProductRepositoryImpl implements ProductRepository {
} else if (sp.length > 0) {
return sp;
}
}

@override
Future<List<StoreProduct>> fetchVegetables() async {
return await _fetch("vegetable");
}

@override
Future<List<StoreProduct>> fetchFruits() async {
return await _fetch("fruit");
}

@override
Future<List<StoreProduct>> fetchDailyEssentials() async {
return await _fetch("dailyEssential");
return null;
}

refreshToken() async {
Expand All @@ -70,7 +55,7 @@ class ProductRepositoryImpl implements ProductRepository {

// user=
} on SocketException {
throw FetchDataException("No Internet");
throw FetchDataException('No Internet Connection!');
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/screens/auth/register.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,15 @@ class _RegisterScreenState extends State<RegisterScreen> {
Column(
children: <Widget>[
InputTextField(
key: Key("username"),
labelText: "Username",
controller: _username,
textInputType: TextInputType.text),
SizedBox(
height: 1.5 * SizeConfig.textMultiplier,
),
InputTextField(
key: Key("emailkey"),
labelText: "Email",
controller: _emailAddress,
textInputType: TextInputType.emailAddress),
Expand All @@ -218,6 +220,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
Column(
children: <Widget>[
InputTextField(
key: Key("mobilekey"),
labelText: "Mobile",
controller: _mobile,
textInputType: TextInputType.number,
Expand Down
15 changes: 15 additions & 0 deletions lib/screens/common/animatedCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ class _AnimatedCardState extends State<AnimatedCard>
.details[0]
.quantity
.quantityMetric,
widget
.product
.details[0]
.quantity
.allowedQuantities[
i]
.value,
widget
.product
.details[0]
Expand Down Expand Up @@ -312,6 +319,14 @@ class _AnimatedCardState extends State<AnimatedCard>
0]
.quantity
.quantityMetric,
widget
.product
.details[
0]
.quantity
.allowedQuantities[
i]
.value,
widget
.product
.details[
Expand Down
10 changes: 10 additions & 0 deletions lib/screens/common/cartIcon.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Copyright 2020 SEVA AUTHORS. All Rights Reserved.
//
// (change the version and the date whenver anyone worked upon this file)
// Version-0.5.2
// Date-{02-10-2020}
///
/// @fileoverview common cart icon : used in multiple pags
/// files.
///
import 'package:flutter/material.dart';
import 'package:mvp/constants/themeColours.dart';
import 'package:mvp/models/newCart.dart';
Expand Down
10 changes: 7 additions & 3 deletions lib/screens/common/common_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ import 'package:mvp/constants/themeColours.dart';

class HelperFunctions {
static void helper(int index, NewCartModel newCart, bool addToCart,
StoreProduct product, String mainUnit, String clickedUnit) {
StoreProduct product, String mainUnit, int value, String clickedUnit) {
double p, q;

// Kg, Kgs, Gms, Pc - Types of Quantities

// For Kg & Pc

for (var i in product.details[0].quantity.allowedQuantities) {
if (i.metric == clickedUnit && !clickedUnit.contains(mainUnit)) {
if (i.metric == clickedUnit &&
!clickedUnit.contains(mainUnit) &&
i.value == value) {
q = 1 * (i.value) / 1000.0;
p = q * double.parse("${product.details[0].price}");
} else if (i.metric.contains(clickedUnit)) {
break;
} else if (i.metric.contains(clickedUnit) &&
clickedUnit.contains(mainUnit)) {
q = double.parse("${i.value}" * 1);
p = q * double.parse("${product.details[0].price}");
break;
Expand Down
161 changes: 161 additions & 0 deletions lib/screens/common/customappBar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// Copyright 2020 SEVA AUTHORS. All Rights Reserved.
//
// (change the version and the date whenver anyone worked upon this file)
// Version-0.5.2
// Date-{02-10-2020}
///
/// @fileoverview Custom Appbar : Customized Appbar used in Main Landing
/// files.
///
import 'dart:convert';
import 'package:http/http.dart' as http;

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mvp/classes/prefrenses.dart';
import 'package:mvp/constants/apiCalls.dart';
import 'package:mvp/constants/themeColours.dart';
import 'package:mvp/screens/common/cartIcon.dart';
import 'package:mvp/screens/location.dart';
import 'package:mvp/sizeconfig/sizeconfig.dart';

class CustomAppBar extends PreferredSize {
final GlobalKey<ScaffoldState> scaffoldKey;
final double height;
final String email;
CustomAppBar(
{@required this.scaffoldKey, this.height = kToolbarHeight, this.email});

@override
Size get preferredSize => Size.fromHeight(height);

//This function shows the user's address in a dialog box
// and the user can edit the address from their also
_showLocation(context) {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))),
title: Text(
"Delivery Address:",
style: TextStyle(
fontSize: 17.0,
color: Colors.black,
fontWeight: FontWeight.w500),
),
content: FutureBuilder(
future: _fetchUserAddress(),
builder: (context, data) {
if (data.hasData) {
return StatefulBuilder(builder: (context, setState) {
return Container(
height: 120.0,
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 10.0),
Container(
width: MediaQuery.of(context).size.width * 0.6,
child: Text(
data.data,
overflow: TextOverflow.clip,
),
),
SizedBox(height: 30.0),
],
),
);
});
} else
return Container(child: Text("Loading Address ..."));
}),
actions: <Widget>[
FutureBuilder(
future: _fetchUserAddress(),
builder: (context, data) {
if (data.hasData) {
return RaisedButton(
onPressed: () {
Navigator.of(context).push(CupertinoPageRoute<Null>(
builder: (BuildContext context) {
return GoogleLocationScreen(
userEmail: email,
);
}));
},
child: Text("Change"),
color: ThemeColoursSeva().pallete1,
textColor: Colors.white,
);
} else
return Container();
},
),
],
);
},
);
}

//To get the address of the user address on clicking the
// location icon
Future<String> _fetchUserAddress() async {
// ignore: unused_local_variable
var mail = email;
final p = await Preferences.getInstance();
String token = await p.getData("token");
String id = await p.getData("id");
Map<String, String> requestHeaders = {'x-auth-token': token};
String url = APIService.getAddressAPI + "$id";
var response = await http.get(url, headers: requestHeaders);
if (response.statusCode == 200) {
// got address
mail = json.decode(response.body)["email"];
return (json.decode(response.body)["address"]);
} else {
throw Exception('something is wrong');
}
}

@override
Widget build(BuildContext context) {
return Container(
color: ThemeColoursSeva().pallete3,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(Icons.menu),
onPressed: () {
scaffoldKey.currentState.openDrawer();
},
iconSize: 28.0,
),
Text(
"Welcome",
style: TextStyle(
color: ThemeColoursSeva().dkGreen,
fontSize: 3.30 * SizeConfig.textMultiplier,
fontWeight: FontWeight.bold),
),
Row(
children: [
IconButton(
icon: Icon(Icons.location_on),
onPressed: () {
_showLocation(context);
},
iconSize: 28.0,
),
CartIcon(),
],
),
],
),
);
}
}
Loading

0 comments on commit 551b531

Please sign in to comment.