diff --git a/lib/constants/apiCalls.dart b/lib/constants/apiCalls.dart index 88264a0..9942560 100644 --- a/lib/constants/apiCalls.dart +++ b/lib/constants/apiCalls.dart @@ -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/"; diff --git a/lib/screens/landing/common/showCards.dart b/lib/screens/landing/common/showCards.dart index 50ee8c3..5da6a59 100644 --- a/lib/screens/landing/common/showCards.dart +++ b/lib/screens/landing/common/showCards.dart @@ -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 { + 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 @@ -34,9 +63,9 @@ class ShowCards extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - store + widget.store ? Text( - "${sp.name}", + "${widget.sp.name}", overflow: TextOverflow.clip, style: TextStyle( color: ThemeColoursSeva().pallete1, @@ -47,15 +76,15 @@ 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, @@ -63,7 +92,7 @@ class ShowCards extends StatelessWidget { fontWeight: FontWeight.w700), ) : Text( - "${sp.name}", + "${widget.sp.name}", overflow: TextOverflow.clip, style: TextStyle( color: ThemeColoursSeva().pallete1, diff --git a/lib/screens/landing/mainLanding.dart b/lib/screens/landing/mainLanding.dart index df7d6ea..18f8096 100644 --- a/lib/screens/landing/mainLanding.dart +++ b/lib/screens/landing/mainLanding.dart @@ -26,12 +26,7 @@ class _MainLandingScreenState extends State { "Free Delivery on your first 3 orders.\n" + "\nOrder Now!", "Get a cashback of Rs 30 on your 4th order!" ]; - List products = []; List categories = []; - // static products - StoreProduct a; - StoreProduct b; - StoreProduct c; // static categories StoreProduct d; StoreProduct e; @@ -42,30 +37,6 @@ class _MainLandingScreenState extends State { @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: @@ -108,6 +79,19 @@ class _MainLandingScreenState extends State { } } + Future> _fetchBestSellers() async { + StorageSharedPrefs p = new StorageSharedPrefs(); + String token = await p.getToken(); + Map 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, @@ -183,7 +167,7 @@ class _MainLandingScreenState extends State { children: [ Expanded( child: ListView.builder( - itemCount: 3, + itemCount: itemsList.length, scrollDirection: Axis.horizontal, itemBuilder: (context, index) { return Row( @@ -359,7 +343,21 @@ class _MainLandingScreenState extends State { 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 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), diff --git a/pubspec.lock b/pubspec.lock index 43ea0d4..0210825 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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" @@ -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: @@ -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: @@ -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: diff --git a/pubspec.yaml b/pubspec.yaml index c33db0c..62b094f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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" @@ -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 @@ -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