From ab1e47dfee0b903bb74b061e7bbf8dae4caeee7a Mon Sep 17 00:00:00 2001 From: Jonasz Bigda Date: Tue, 1 Dec 2020 19:50:24 +0100 Subject: [PATCH] Multi price --- lib/components/dishCard.dart | 40 ++++++++++++++++++++++++++++++++---- lib/services.dart | 34 ++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/lib/components/dishCard.dart b/lib/components/dishCard.dart index aab6b98..6d09573 100644 --- a/lib/components/dishCard.dart +++ b/lib/components/dishCard.dart @@ -53,10 +53,7 @@ class DishCard extends StatelessWidget { ), ], ), - Text( - '${dish.price} zł', - style: TextStyle(color: Colors.white, fontSize: 14), - ), + Prices(prices: dish.prices) ], )), Container( @@ -72,3 +69,38 @@ class DishCard extends StatelessWidget { ); } } + +class Prices extends StatelessWidget { + final MenuiPrices prices; + + Prices({@required this.prices}); + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + if (prices.price1.priceName == "") + Text( + '${prices.price1.price} zł', + style: TextStyle(color: Colors.white, fontSize: 14), + ), + if (prices.price1.priceName != "") + Text( + '${prices.price1.priceName}: ${prices.price1.price} zł', + style: TextStyle(color: Colors.white, fontSize: 14), + ), + if (prices.price2.priceName != "") + Text( + '${prices.price2.priceName}: ${prices.price2.price} zł', + style: TextStyle(color: Colors.white, fontSize: 14), + ), + if (prices.price3.priceName != "") + Text( + '${prices.price3.priceName}: ${prices.price3.price} zł', + style: TextStyle(color: Colors.white, fontSize: 14), + ), + ], + ); + } +} diff --git a/lib/services.dart b/lib/services.dart index a0c8ca1..85afc3c 100644 --- a/lib/services.dart +++ b/lib/services.dart @@ -3,7 +3,7 @@ import 'package:http/http.dart' as http; import 'package:flutter/foundation.dart'; class MenuiServices { - final String backendURL = 'https://menui.azurewebsites.net/'; + final String backendURL = 'https://api.menui.pl/'; Future> fetchAutocomplete(String text) async { final response = @@ -49,12 +49,22 @@ class MenuiServices { if (decodedResponse.isNotEmpty && decodedResponse != null) { for (var dish in decodedResponse) { final thisAllergens = dish['allergens']; + final thisPrices = dish['prices']; + final thisPrice1 = thisPrices['price1']; + final thisPrice2 = thisPrices['price2']; + final thisPrice3 = thisPrices['price3']; final Dish thisDish = new Dish( id: dish['_id'], restaurantId: dish['restaurantId'], name: dish['name'], category: dish['category'], - price: dish['price'], + prices: new MenuiPrices( + price1: new MenuiPrice( + thisPrice1['priceName'], thisPrice1['price']), + price2: new MenuiPrice( + thisPrice2['priceName'], thisPrice2['price']), + price3: new MenuiPrice( + thisPrice3['priceName'], thisPrice3['price'])), notes: dish['notes'], imgUrl: dish['imgUrl'], weight: dish['weight'], @@ -275,7 +285,7 @@ class Dish { String restaurantId; String name; String category; - String price; + MenuiPrices prices; String notes; String imgUrl; String weight; @@ -291,7 +301,7 @@ class Dish { @required this.restaurantId, @required this.name, @required this.category, - this.price, + this.prices, this.notes, this.imgUrl, this.weight, @@ -303,6 +313,22 @@ class Dish { this.vegetarian}); } +class MenuiPrices { + MenuiPrice price1; + MenuiPrice price2; + MenuiPrice price3; + + MenuiPrices( + {@required this.price1, @required this.price2, @required this.price3}); +} + +class MenuiPrice { + String priceName; + String price; + + MenuiPrice(this.priceName, this.price); +} + class MenuiAllergens { bool gluten; bool lactose;