Skip to content

Commit

Permalink
finished random restaurant options tab
Browse files Browse the repository at this point in the history
  • Loading branch information
JTP75 committed Dec 9, 2023
1 parent 567878a commit b3ac916
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 17 deletions.
1 change: 1 addition & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
13 changes: 12 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,18 @@ class HomePage extends StatelessWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
CriteriaBox(
ExpansionTile(
title: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Search options",
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
),
children: [CriteriaBox()]
)
],
),
Expand Down
284 changes: 268 additions & 16 deletions lib/page_assets/home.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
import 'package:flutter/material.dart';
import 'package:restaurant_app/page_assets/home_backend.dart';

const List<String> priceRangeEntries = ["\$","\$\$","\$\$\$"];
//const List<String> priceRangeEntries = ["hello"];
const List<String> priceRangeEntries = ["Any","\$","\$\$","\$\$\$"];
const List<String> foodTypeEntries = [
"Any",
"Breakfast",
"Pizza",
"Mexican",
"Burgers",
"Chinese",
"Sandwiches",
"Seafood",
"Thai",
"Italian",
"Korean",
"Japanese",
"Steakhouses",
"Vietnamese",
"Vegetarian",
"Sushi Bars",
"American"
];
const List<int> travelDistanceEntries = [1,5,10,20,-1];

HomePageBackend homePageBackend = HomePageBackend();

class CriteriaBox extends Card {

Expand All @@ -15,28 +37,73 @@ class CriteriaBox extends Card {
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Options",
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
),
),
child: Column(
children: [
Row(
children: [
Text(
"Price Range"
),
Spacer(
flex: 1,
),
PriceDropdown()
],
),
]
)
),
Divider(),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Row(
children: [
Text(
"Price Range"
"Food Category"
),
Spacer(
flex: 1,
),
MyDropdownButton()
FoodDropdown()
],
),
]
)
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Row(
children: [
Text(
"Dietary Restrictions"
),
Spacer(
flex: 1,
),
DietaryRestrictionsButton(
)
],
),
]
)
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Row(
children: [
Text(
"Travel Distance"
),
Spacer(
flex: 1,
),
TravelDistanceDropdown(
)
],
),
]
Expand All @@ -49,14 +116,14 @@ class CriteriaBox extends Card {

}

class MyDropdownButton extends StatefulWidget {
class PriceDropdown extends StatefulWidget {
@override
State<StatefulWidget> createState() => MyDropdownButtonState();
State<StatefulWidget> createState() => PriceDropdownState();

}

class MyDropdownButtonState extends State<MyDropdownButton> {
String selectedValue = priceRangeEntries.first;
class PriceDropdownState extends State<PriceDropdown> {
String selectedValue = homePageBackend.priceRange;

@override
Widget build(BuildContext context) {
Expand All @@ -66,6 +133,7 @@ class MyDropdownButtonState extends State<MyDropdownButton> {
setState(() {
selectedValue = newValue!;
});
homePageBackend.priceRange = newValue!;
},
items: priceRangeEntries.map<DropdownMenuItem<String>>(
(String value) {
Expand All @@ -77,4 +145,188 @@ class MyDropdownButtonState extends State<MyDropdownButton> {
).toList(),
);
}
}

class FoodDropdown extends StatefulWidget {
@override
State<StatefulWidget> createState() => FoodDropdownState();

}

class FoodDropdownState extends State<FoodDropdown> {
String selectedValue = homePageBackend.foodType;

@override
Widget build(BuildContext context) {
return DropdownButton<String>(
value: selectedValue,
onChanged: (String? newValue) {
setState(() {
selectedValue = newValue!;
});
homePageBackend.foodType = newValue!;
},
items: foodTypeEntries.map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}
).toList(),
);
}
}

class DietaryRestrictionsButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return DietaryRestrictionsDialog();
},
);
},
child: Text("Edit"),
);
}
}
class DietaryRestrictionsDialog extends StatefulWidget {
@override
State<StatefulWidget> createState() => DietaryRestrictionsDialogState();
}

class DietaryRestrictionsDialogState extends State<DietaryRestrictionsDialog> {

DietaryRestrictions dr = homePageBackend.dietaryRestrictions;

@override
Widget build(BuildContext context) {
return AlertDialog(
title: Text('Dietary Restrictions'),
content: Column(
children: [
CheckboxListTile(
title: Text("Gluten-free"),
value: dr.glutenFree,
onChanged: (value) {
setState (() {
dr.glutenFree = value!;
});
homePageBackend.dietaryRestrictions.glutenFree = value!;
}
),
CheckboxListTile(
title: Text("Halal"),
value: dr.halal,
onChanged: (value) {
setState (() {
dr.halal = value!;
});
homePageBackend.dietaryRestrictions.halal = value!;
}
),
CheckboxListTile(
title: Text("Keto"),
value: dr.keto,
onChanged: (value) {
setState (() {
dr.keto = value!;
});
homePageBackend.dietaryRestrictions.keto = value!;
}
),
CheckboxListTile(
title: Text("Kosher"),
value: dr.kosher,
onChanged: (value) {
setState (() {
dr.kosher = value!;
});
homePageBackend.dietaryRestrictions.kosher = value!;
}
),
CheckboxListTile(
title: Text("Pescatarian"),
value: dr.pescatarian,
onChanged: (value) {
setState (() {
dr.pescatarian = value!;
});
homePageBackend.dietaryRestrictions.pescatarian = value!;
}
),
CheckboxListTile(
title: Text("Vegetarian"),
value: dr.vegetarian,
onChanged: (value) {
setState (() {
dr.vegetarian = value!;
});
homePageBackend.dietaryRestrictions.vegetarian = value!;
}
),
CheckboxListTile(
title: Text("Vegan"),
value: dr.vegan,
onChanged: (value) {
setState (() {
dr.vegan = value!;
});
homePageBackend.dietaryRestrictions.vegan = value!;
}
),
],
),
actions: [
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Close'),
),
],
);
}
}

class TravelDistanceDropdown extends StatefulWidget {
@override
State<StatefulWidget> createState() => TravelDistanceDropdownState();
}

String travelDistanceDisplay(int distance) {
if (distance>0) {
return "Within $distance miles";
} else {
return "Any distance";
}
}

class TravelDistanceDropdownState extends State<TravelDistanceDropdown> {
int selectedValue = homePageBackend.maxDistanceMiles;

@override
Widget build(BuildContext context) {
return DropdownButton<int>(
value: selectedValue,
onChanged: (int? newValue) {
setState(() {
selectedValue = newValue!;
});
homePageBackend.maxDistanceMiles = newValue!;
},
items: travelDistanceEntries.map<DropdownMenuItem<int>>(
(int value) {
return DropdownMenuItem<int>(
value: value,
child: Text(travelDistanceDisplay(value))
);
}
).toList(),
);
}
}
34 changes: 34 additions & 0 deletions lib/page_assets/home_backend.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class HomePageBackend {
String priceRange = "Any";
String foodType = "Any";
DietaryRestrictions dietaryRestrictions = DietaryRestrictions();
int maxDistanceMiles = 10;

HomePageBackend() {
priceRange = "Any";
foodType = "Any";
dietaryRestrictions = DietaryRestrictions();

print(dietaryRestrictions);
}
}

class DietaryRestrictions {
bool glutenFree = false;
bool halal = false;
bool keto = false;
bool kosher = false;
bool pescatarian = false;
bool vegetarian = false;
bool vegan = false;

DietaryRestrictions() {
glutenFree = false;
halal = false;
keto = false;
kosher = false;
pescatarian = false;
vegetarian = false;
vegan = false;
}
}

0 comments on commit b3ac916

Please sign in to comment.