Skip to content

Commit

Permalink
Merge pull request #67 from Onestop-Agrotech/release1
Browse files Browse the repository at this point in the history
Release1
  • Loading branch information
Rahul-Vijay authored Aug 16, 2020
2 parents dc00d05 + de85343 commit c386463
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 95 deletions.
3 changes: 3 additions & 0 deletions lib/constants/apiCalls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class APIService {
// storesList.dart - _fetchUserAddress function
static final String getAddressAPI = "$_api/users/user-address/";

// PRODUCTS
static final String getBestSellersAPI = "$_api/products/all/bestsellers";

// ORDERS
// shopping cart file - _postOrderToServer function
static final String ordersAPI = "$_api/orders/";
Expand Down
47 changes: 38 additions & 9 deletions lib/screens/landing/common/showCards.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,53 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:mvp/constants/themeColours.dart';
import 'package:mvp/models/storeProducts.dart';
import 'package:mvp/screens/common/AnimatedCard/modalContainer.dart';
import 'package:mvp/screens/products/products.dart';

class ShowCards extends StatelessWidget {
class ShowCards extends StatefulWidget {
final StoreProduct sp;
final bool store;
final int index;
ShowCards({this.sp, this.store, @required this.index});

@override
_ShowCardsState createState() => _ShowCardsState();
}

class _ShowCardsState extends State<ShowCards> {
void onClickProduct() {
showGeneralDialog(
context: context,
barrierDismissible: true,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
barrierColor: Colors.black45,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (BuildContext buildContext, Animation animation,
Animation secondaryAnimation) {
return Center(
child: AddItemModal(
product: widget.sp,
));
});
}

@override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return GestureDetector(
onTap: () {
if (!this.store)
if (!this.widget.store)
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Products(type: this.index)),
MaterialPageRoute(
builder: (context) => Products(type: this.widget.index)),
);
else {
// open the modal container
onClickProduct();
}
},
child: Container(
// fallback height
Expand All @@ -34,9 +63,9 @@ class ShowCards extends StatelessWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
store
widget.store
? Text(
"${sp.name}",
"${widget.sp.name}",
overflow: TextOverflow.clip,
style: TextStyle(
color: ThemeColoursSeva().pallete1,
Expand All @@ -47,23 +76,23 @@ class ShowCards extends StatelessWidget {
Container(
height: height * 0.1,
child: CachedNetworkImage(
imageUrl: sp.pictureUrl,
imageUrl: widget.sp.pictureUrl,
placeholder: (context, url) =>
Container(height: 50.0, child: Text("Loading...")),
errorWidget: (context, url, error) => Icon(Icons.error),
),
),
store
widget.store
? Text(
"Rs ${sp.price} - ${sp.quantity.quantityValue} ${sp.quantity.quantityMetric}",
"Rs ${widget.sp.price} - ${widget.sp.quantity.quantityValue} ${widget.sp.quantity.quantityMetric}",
overflow: TextOverflow.clip,
style: TextStyle(
color: ThemeColoursSeva().pallete1,
fontSize: 15.0,
fontWeight: FontWeight.w700),
)
: Text(
"${sp.name}",
"${widget.sp.name}",
overflow: TextOverflow.clip,
style: TextStyle(
color: ThemeColoursSeva().pallete1,
Expand Down
60 changes: 29 additions & 31 deletions lib/screens/landing/mainLanding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ class _MainLandingScreenState extends State<MainLandingScreen> {
"Free Delivery on your first 3 orders.\n" + "\nOrder Now!",
"Get a cashback of Rs 30 on your 4th order!"
];
List<StoreProduct> products = [];
List<StoreProduct> categories = [];
// static products
StoreProduct a;
StoreProduct b;
StoreProduct c;
// static categories
StoreProduct d;
StoreProduct e;
Expand All @@ -42,30 +37,6 @@ class _MainLandingScreenState extends State<MainLandingScreen> {
@override
initState() {
super.initState();
Quantity q = new Quantity(quantityValue: 1, quantityMetric: "Kg");
a = new StoreProduct(
name: "Apple",
pictureUrl: "https://storepictures.theonestop.co.in/products/apple.jpg",
quantity: q,
description: "local",
price: 250);
b = new StoreProduct(
name: "Onion",
pictureUrl: "https://storepictures.theonestop.co.in/products/onion.jpg",
quantity: q,
description: "local",
price: 18,
);
c = new StoreProduct(
name: "Carrots",
pictureUrl:
"https://storepictures.theonestop.co.in/products/carrot.jpg",
quantity: q,
description: "local",
price: 30);
products.add(a);
products.add(b);
products.add(c);
d = new StoreProduct(
name: "Vegetables",
pictureUrl:
Expand Down Expand Up @@ -108,6 +79,19 @@ class _MainLandingScreenState extends State<MainLandingScreen> {
}
}

Future<List<StoreProduct>> _fetchBestSellers() async {
StorageSharedPrefs p = new StorageSharedPrefs();
String token = await p.getToken();
Map<String, String> requestHeaders = {'x-auth-token': token};
String url = APIService.getBestSellersAPI;
var response = await http.get(url, headers: requestHeaders);
if (response.statusCode == 200) {
return jsonToStoreProductModel(response.body);
} else {
throw Exception('something is wrong');
}
}

_showLocation() {
showDialog(
context: context,
Expand Down Expand Up @@ -183,7 +167,7 @@ class _MainLandingScreenState extends State<MainLandingScreen> {
children: <Widget>[
Expanded(
child: ListView.builder(
itemCount: 3,
itemCount: itemsList.length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return Row(
Expand Down Expand Up @@ -359,7 +343,21 @@ class _MainLandingScreenState extends State<MainLandingScreen> {
SizedBox(height: 9.0),
commonText(height, "Best Sellers", ""),
SizedBox(height: 9.0),
commonWidget(height, products, true),
FutureBuilder(
future: _fetchBestSellers(),
builder: (builder, snapshot) {
if (snapshot.hasData) {
List<StoreProduct> bestSellers = snapshot.data;
if (bestSellers.length > 0) {
return commonWidget(height, bestSellers, true);
} else
return Container(
child:
Center(child: Text("No products found!")),
);
}
return Container();
}),
SizedBox(height: 9.0),
commonText(height, "Categories", ""),
SizedBox(height: 9.0),
Expand Down
51 changes: 1 addition & 50 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ packages:
source: hosted
version: "1.4.0"
flutter_native_splash:
dependency: "direct main"
dependency: "direct dev"
description:
name: flutter_native_splash
url: "https://pub.dartlang.org"
Expand Down Expand Up @@ -387,13 +387,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
platform_detect:
dependency: transitive
description:
name: platform_detect
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
plugin_platform_interface:
dependency: transitive
description:
Expand All @@ -415,13 +408,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.2"
pub_semver:
dependency: transitive
description:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.4"
quiver:
dependency: transitive
description:
Expand Down Expand Up @@ -553,41 +539,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "5.5.0"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+7"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.7"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
uuid:
dependency: transitive
description:
Expand Down
8 changes: 3 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+4
version: 1.0.0+5

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down Expand Up @@ -45,12 +45,8 @@ dependencies:
razorpay_flutter: ^1.2.1
# for otp login field
otp_text_field: ^1.0.1
# launch urls
url_launcher: ^5.5.0
# firebase messaging - notifs
firebase_messaging: ^6.0.16
# splash screen
flutter_native_splash: ^0.1.9
# for location
location: ^3.0.0
# for in-app updates
Expand All @@ -65,6 +61,8 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
# splash screen
flutter_native_splash: ^0.1.9

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down

0 comments on commit c386463

Please sign in to comment.