Display dish list
This commit is contained in:
63
lib/components/dishCard.dart
Normal file
63
lib/components/dishCard.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../services.dart';
|
||||
|
||||
class DishCard extends StatelessWidget {
|
||||
final Dish dish;
|
||||
|
||||
DishCard({@required this.dish});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
color: Colors.grey[800],
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
margin: EdgeInsets.symmetric(horizontal: 12, vertical: 5),
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: ClipRRect(
|
||||
child: Image.network(
|
||||
dish.imgUrl,
|
||||
width: 80,
|
||||
height: 80,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(12),
|
||||
topLeft: Radius.circular(12)),
|
||||
),
|
||||
padding: EdgeInsets.only(right: 8),
|
||||
),
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
dish.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
style: TextStyle(color: Colors.orange[600], fontSize: 16),
|
||||
),
|
||||
Text(
|
||||
'${dish.price} zł',
|
||||
style: TextStyle(color: Colors.grey[300], fontSize: 14),
|
||||
),
|
||||
],
|
||||
)),
|
||||
Container(
|
||||
child: Icon(
|
||||
Icons.arrow_right,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
152
lib/components/dishList.dart
Normal file
152
lib/components/dishList.dart
Normal file
@@ -0,0 +1,152 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../services.dart';
|
||||
import 'dishCard.dart';
|
||||
|
||||
class DishList extends StatelessWidget {
|
||||
final String id;
|
||||
final List<String> categories;
|
||||
DishList({@required this.id, @required this.categories});
|
||||
|
||||
final MenuiServices services = new MenuiServices();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(children: [
|
||||
ListView(children: [
|
||||
SizedBox(height: 24),
|
||||
FutureBuilder<List<Dish>>(
|
||||
future: services.fetchAllDishes(id),
|
||||
builder:
|
||||
(BuildContext context, AsyncSnapshot<List<Dish>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final List<Dish> dishes = snapshot.data;
|
||||
return ListView.builder(
|
||||
controller: ScrollController(),
|
||||
shrinkWrap: true,
|
||||
itemCount: categories.length,
|
||||
itemBuilder: (context, index) {
|
||||
final filteredDishes =
|
||||
filterDishesByCategory(dishes, categories[index]);
|
||||
return ExpansionTile(
|
||||
leading: Icon(
|
||||
Icons.fastfood_rounded,
|
||||
color: Colors.orange,
|
||||
),
|
||||
title: Text(
|
||||
categories[index],
|
||||
style: TextStyle(color: Colors.grey[300]),
|
||||
),
|
||||
children: <Widget>[
|
||||
ListView.builder(
|
||||
primary: false,
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
itemCount: filteredDishes.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Container(
|
||||
child: DishCard(dish: filteredDishes[index]),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
}),
|
||||
]),
|
||||
Positioned.fill(
|
||||
bottom: 20,
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: FloatingActionButton.extended(
|
||||
backgroundColor: Colors.grey[900],
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.keyboard_arrow_down_rounded,
|
||||
color: Colors.orange,
|
||||
),
|
||||
label: Text(
|
||||
'Zamknij',
|
||||
style:
|
||||
TextStyle(color: Colors.white, fontWeight: FontWeight.w400),
|
||||
),
|
||||
),
|
||||
))
|
||||
]);
|
||||
}
|
||||
|
||||
List<Dish> filterDishesByCategory(List<Dish> dishes, String category) {
|
||||
List<Dish> result = [];
|
||||
for (var dish in dishes) {
|
||||
if (dish.category == category) {
|
||||
result.add(dish);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
class DishList extends StatelessWidget {
|
||||
final String id;
|
||||
final List<String> categories;
|
||||
DishList({@required this.id, @required this.categories});
|
||||
|
||||
final MenuiServices services = new MenuiServices();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(children: [
|
||||
FutureBuilder<List<Dish>>(
|
||||
future: services.fetchAllDishes(id),
|
||||
builder: (BuildContext context, AsyncSnapshot<List<Dish>> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final List<Dish> dishes = snapshot.data;
|
||||
return ListView.builder(
|
||||
controller: ScrollController(),
|
||||
shrinkWrap: true,
|
||||
itemCount: categories.length,
|
||||
itemBuilder: (context, index) {
|
||||
final filteredDishes =
|
||||
filterDishesByCategory(dishes, categories[index]);
|
||||
return ExpansionTile(
|
||||
leading: Icon(
|
||||
Icons.fastfood_rounded,
|
||||
color: Colors.orange,
|
||||
),
|
||||
title: Text(
|
||||
categories[index],
|
||||
style: TextStyle(color: Colors.grey[300]),
|
||||
),
|
||||
children: <Widget>[
|
||||
ListView.builder(
|
||||
primary: false,
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
itemCount: filteredDishes.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Container(
|
||||
child: DishCard(dish: filteredDishes[index]),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
}),
|
||||
|
||||
]);
|
||||
} */
|
||||
10
lib/components/mapWithMarkers.dart
Normal file
10
lib/components/mapWithMarkers.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
/* import 'package:flutter/material.dart';
|
||||
import '../services.dart'; */
|
||||
/*
|
||||
class MapWithMarkers extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../services.dart';
|
||||
import 'lineOfIcons.dart';
|
||||
import 'dishList.dart';
|
||||
|
||||
class RestaurantView extends StatelessWidget {
|
||||
final String id;
|
||||
@@ -10,6 +11,8 @@ class RestaurantView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
services.fetchAllDishes(id);
|
||||
List<String> categories = [];
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
decoration: BoxDecoration(color: Colors.grey[850]),
|
||||
@@ -19,6 +22,7 @@ class RestaurantView extends StatelessWidget {
|
||||
(BuildContext context, AsyncSnapshot<Restaurant> snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
final Restaurant restaurant = snapshot.data;
|
||||
categories = restaurant.categories;
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
@@ -154,11 +158,11 @@ class RestaurantView extends StatelessWidget {
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
showMenu(context);
|
||||
showMenu(context, categories);
|
||||
},
|
||||
label: Text(
|
||||
'Pokaż menu',
|
||||
style: TextStyle(color: Colors.white),
|
||||
'Menu',
|
||||
style: TextStyle(color: Colors.white, fontWeight: FontWeight.w400),
|
||||
),
|
||||
icon: Icon(
|
||||
Icons.arrow_upward_rounded,
|
||||
@@ -168,17 +172,19 @@ class RestaurantView extends StatelessWidget {
|
||||
));
|
||||
}
|
||||
|
||||
showMenu(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)),
|
||||
child: Text('qweqweqweqweqweqw'),
|
||||
);
|
||||
});
|
||||
showMenu(BuildContext context, List<String> categories) {
|
||||
if (categories.isNotEmpty) {
|
||||
showModalBottomSheet(
|
||||
backgroundColor: Colors.grey[850],
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return DishList(
|
||||
categories: categories,
|
||||
id: id,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user