Skip to content

Commit

Permalink
feat: add to cart method
Browse files Browse the repository at this point in the history
  • Loading branch information
Rizz-33 committed Mar 25, 2024
1 parent e11f151 commit c11499e
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/pages/food.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:blend_bristo/components/button.dart';
import 'package:blend_bristo/models/food.dart';
import 'package:blend_bristo/models/restaurant.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class FoodPage extends StatefulWidget {
final Food food;
Expand All @@ -17,6 +19,24 @@ class FoodPage extends StatefulWidget {
}

class _FoodPageState extends State<FoodPage> {

//method to add to cart
void addToCart(Food food, Map<Addon, bool> selectedAddons){
//close the current food page to go back to menu
Navigator.pop(context);

//format the selected addons
List<Addon> currentlySelectedAddons = [];
for (Addon addon in widget.food.availableAddon) {
if (widget.selectedAddons[addon] == true) {
currentlySelectedAddons.add(addon);
}
}

//add to cart
context.read<Restaurant>().addToCart(food, currentlySelectedAddons);
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -123,9 +143,7 @@ class _FoodPageState extends State<FoodPage> {
padding: const EdgeInsets.only(bottom: 25.0),
child: MyButton(
text: 'Add To Cart',
onTap: () {
// Your button onTap functionality
},
onTap: () => addToCart(widget.food, widget.selectedAddons),
),
),
),
Expand Down

0 comments on commit c11499e

Please sign in to comment.