Food Ordering Native APP: ADV-C43
Food Ordering Native APP: ADV-C43
Once the user selects the item, it would show the price of the item and option to choose the
quantity. Once all the things were done, the user could place the order. And the app would
update the things on firebase realtime database.
1. Initialize all the global variables: We initialized the variables priceList and nameList
to store the empty list of prices and names of all the dishes, which were saved in the
firebase. We set the variables as an empty list.
Once the user confirmed the dishes, we needed to store details of the dishes such as
their names, total quantities, and the total prices in empty global variables. Thus, we
declared three empty global variables with names - finalDishList, finalQuantityList,
and finalPriceList.
2. Added Code for the Menu Screen Initialization: When the Menu screen gets
initialized, we added code to set the ProjectBucket name “price” of the Firebase
database. Then added the code to store all the names, prices and quantities inside
the global variables - finalDishList, finalPriceList, and finalQuantityList from
TinyDB.
*Here price is the bucket name that we choose while creating the firebase realtime
database.
*TinyDB- Tiny Database is used to save the data for your project so that we can use
that data in all the other screens also.
➢ Go to the Menu Block and choose the following block before dropping it on the
screen:
➢ We stored all the names, prices and quantities inside the global variables -
finalDishList, finalPriceList, and finalQuantityList. These values are already
saved in the Tiny database which we have done in the Screen1 of the User
App in the last class.
Choose the “set to” block from Variable block and attach it to the following
block from the TinyDb1 block to get the value:
In the same way, we had done for all the variables such as finalDishList,
finalPriceList, and finalQuantityList:
3. Added Code for Data Changes in the Firebase: When the data changes in the
firebase, we update the changes in global nameList and priceList variables.
So, Fried Rice (dish name) is a tag and 200 (dish price) is a value. We
stored the dish name in nameList and dish price in priceList.
● In the same way, we wrote the code to update the changes in the priceList:
4. Added Code for the Menu Selection by the User: When the user selected any of the
list items from the menu then we had done changes in the component visibility and
added functionalities to them.
● First, we initialized the variable selectedDishPrice to save the price of the
selected dish.
● Once the user picks any of the items from the Menu list then we hide the
ListView1 block.
➢ Set the ListView1 visibility to false.
➢ Set the quantity Text to 0 value. This is because everytime a new dish has
been selected the value of quantity should get zero.
➢ Set the Text of the price to global SelectedDishPrice and assign the value
that we get after joining the string “Cost of the Dish is Rs: ” and the value
that we get from global selectedDishPrice.
5. Added Code when the User Clicks on the Add Sign: Once we clicked on the add
sign, it increased the quantity value by 1 and set the price of the selected dish
according to the quantity chosen by the user.
● We increased the quantity Text value by 1:
● Set the text of price. For this, drag and drop “set price Text to” command from
the price Block and assign the value that we get after joining the string “Rs. ”
with the quantity text that multiplies with the variable global
selectedDishPrice that holds the price of the selected dish.
● Check the condition whether the quantity Text > 0. If this is true, then enable
the confirmDish button otherwise it is disabled.
6. Added Code when the User Clicks on the Subtract Sign: In the same way, we did
the coding for the sub block. Once we click on the subtract sign, it decreases the
quantity value by 1 and sets the price of the selected dish according to the quantity
chosen by the user.
● We decreased the quantity Text value by 1.
● Set the text of price. For this, drag and drop “set price Text to” command from
the price Block and assign the value that we get after joining the string “Rs. ”
with the quantity Text that multiplies with the variable global
selectedDishPrice that holds the price of the selected dish.
● We check the condition whether the quantity Text < 1, then only:
○ Made the ListView1 Visible again.
○ quantitySection Invisible.
○ Disable the confirmDish button.
What’s NEXT?
In the next class, we will complete the coding for the “Confirm this dish” and “Don’t want
this dish back to menu” buttons of the Menu screen of the User App. We will also create a
function “cartSummary” and call it inside the necessary blocks.