This commit is contained in:
2021-01-08 15:20:27 +01:00
parent c75420a29e
commit 14f36bc01e
7 changed files with 380 additions and 219 deletions

View File

@@ -1,11 +1,26 @@
import 'package:flutter/material.dart';
import 'package:menui_mobile/components/restaurantCardAsync.dart';
import '../settings.dart';
import 'homeScreen.dart';
import 'orderView.dart';
import 'menuiButton.dart';
class FavoritesView extends StatelessWidget {
final settings = new MenuiSettings();
class FavoritesView extends StatefulWidget {
const FavoritesView({Key key}) : super(key: key);
@override
_FavoritesViewState createState() => _FavoritesViewState();
}
class _FavoritesViewState extends State<FavoritesView> {
final MenuiSettings settings = new MenuiSettings();
Future<List<String>> favorites;
@override
void initState() {
super.initState();
favorites = settings.getFavs();
}
@override
Widget build(BuildContext context) {
@@ -14,57 +29,24 @@ class FavoritesView extends StatelessWidget {
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)),
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(color: Colors.grey[900]),
child: Column(
children: [
SizedBox(
height: 20,
),
Container(
decoration: BoxDecoration(color: Colors.grey[900]),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RaisedButton(
color: Colors.grey[900],
elevation: 0,
padding:
EdgeInsets.symmetric(vertical: 12, horizontal: 4),
onPressed: () {
Navigator.pop(context);
child: FutureBuilder(
future: favorites,
builder: (context, snapshot) {
if (snapshot.hasData) {
List<String> result = snapshot.data;
return ListView.builder(
itemCount: result.length,
itemBuilder: (context, index) {
return RestaurantCardAsync(
id: result[index],
);
},
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(
Icons.arrow_back_rounded,
color: Colors.orange,
),
Text(
'Cofnij',
style: TextStyle(
color: Colors.grey[200],
fontSize: 12,
fontWeight: FontWeight.w400),
)
],
),
),
Row(
children: [],
)
],
),
)
],
),
),
],
),
),
);
} else {
return null;
}
},
)),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: Container(
decoration: BoxDecoration(color: Colors.grey[900]),
@@ -75,8 +57,8 @@ class FavoritesView extends StatelessWidget {
color: Colors.orange,
icon: Icons.home_rounded,
text: "Szukaj",
onPressed: () => Navigator.push(
context, MaterialPageRoute(builder: (context) => HomePage())),
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => HomePage())),
),
MenuiButton(
color: Colors.orange,
@@ -102,6 +84,19 @@ class FavoritesView extends StatelessWidget {
],
),
),
);
appBar: AppBar(
title: Text(
'Ulubione',
style: TextStyle(color: Colors.white, fontWeight: FontWeight.w400),
),
backgroundColor: Colors.grey[900],
leading: IconButton(
icon: Icon(
Icons.arrow_back_ios_rounded,
color: Colors.orange,
),
onPressed: () => Navigator.pop(context),
),
));
}
}

View File

@@ -24,7 +24,7 @@ class HomePage extends StatelessWidget {
"img/logo_orange.png",
width: 160,
),
MenuiSearchBar(),
MenuiSearchBar(''),
Text(
'lub',
style: TextStyle(color: Colors.grey[500]),

View File

@@ -16,39 +16,6 @@ class OrderView extends StatelessWidget {
image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)),
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(color: Colors.grey[850]),
child: Column(
children: [
SizedBox(
height: 20,
),
Container(
decoration: BoxDecoration(color: Colors.grey[900]),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
MenuiButton(
color: Colors.orange,
onPressed: () => Navigator.pop(context),
text: "Cofnij",
icon: Icons.arrow_back_rounded,
),
Row(
children: [
MenuiButton(
color: Colors.orange,
onPressed: () {
settings.clearOrder();
},
text: "Wyczyść",
icon: Icons.delete_forever_rounded,
),
],
)
],
),
),
Container(
decoration: BoxDecoration(color: Colors.grey[800]),
child: Row(
@@ -68,9 +35,6 @@ class OrderView extends StatelessWidget {
],
),
),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: Container(
decoration: BoxDecoration(color: Colors.grey[900]),
@@ -81,8 +45,8 @@ class OrderView extends StatelessWidget {
color: Colors.orange,
icon: Icons.home_rounded,
text: "Szukaj",
onPressed: () => Navigator.push(
context, MaterialPageRoute(builder: (context) => HomePage())),
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => HomePage())),
),
MenuiButton(
color: Colors.orange,
@@ -108,6 +72,30 @@ class OrderView extends StatelessWidget {
],
),
),
);
appBar: AppBar(
title: Text(
'Zamówienie',
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.w400, fontSize: 14),
),
backgroundColor: Colors.grey[900],
leading: IconButton(
icon: Icon(
Icons.arrow_back_ios_rounded,
color: Colors.orange,
),
onPressed: () => Navigator.pop(context),
),
actions: [
MenuiButton(
color: Colors.orange,
onPressed: () {
settings.clearOrder();
},
text: "Wyczyść",
icon: Icons.delete_forever_rounded,
),
],
));
}
}

View File

@@ -0,0 +1,142 @@
import 'package:flutter/material.dart';
import 'restaurantView.dart';
import 'package:menui_mobile/services.dart';
import 'lineOfIconsSmall.dart';
class RestaurantCardAsync extends StatelessWidget {
RestaurantCardAsync({@required this.id});
final _services = new MenuiServices();
final String id;
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: Card(
child: FutureBuilder(
future: _services.fetchRestaurant(id),
builder: (context, snapshot) {
if (snapshot.hasData) {
Restaurant restaurant = snapshot.data;
String _openHours =
_services.getTodayHours(restaurant.workingHours);
return InkWell(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
RestaurantView(id: restaurant.id))),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
child: ClipRRect(
child: Image.network(
restaurant.imgUrl,
width: 100,
height: 100,
fit: BoxFit.cover,
),
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(12),
topLeft: Radius.circular(12)),
),
padding: EdgeInsets.only(right: 8),
),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.only(bottom: 4),
child: Text(
restaurant.name,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: TextStyle(
color: Colors.orange[600], fontSize: 14),
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(
Icons.location_city,
size: 14,
color: Colors.white,
),
Padding(
padding: EdgeInsets.only(left: 4),
child: Text(
'${restaurant.city}, ${restaurant.adress}',
style: TextStyle(
color: Colors.grey, fontSize: 11),
),
),
]),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(
Icons.restaurant,
size: 14,
color: Colors.white,
),
Padding(
padding: EdgeInsets.only(left: 4),
child: Text(
'${restaurant.type}',
style: TextStyle(
color: Colors.grey, fontSize: 11),
),
),
]),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(
Icons.timer,
size: 14,
color: Colors.white,
),
Padding(
padding: EdgeInsets.only(left: 4),
child: Text(
'$_openHours',
style: TextStyle(
color: Colors.grey, fontSize: 11),
),
),
]),
Padding(
padding: EdgeInsets.only(top: 2),
child: LineOfIconsSmall(tags: restaurant.tags),
)
],
),
),
Container(
child: Icon(
Icons.arrow_right,
color: Colors.white,
size: 28,
),
)
],
));
} else {
return Center(
child: CircularProgressIndicator(),
);
}
},
),
color: Colors.grey[900],
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(11)),
margin: EdgeInsets.symmetric(horizontal: 12),
),
);
}
}

View File

@@ -3,6 +3,10 @@ import '../services.dart';
import 'searchResults.dart';
class MenuiSearchBar extends StatefulWidget {
final String initialValue;
MenuiSearchBar(this.initialValue);
@override
MenuiSearchBarState createState() {
return MenuiSearchBarState();
@@ -23,6 +27,7 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
@override
void initState() {
super.initState();
_controller.text = widget.initialValue;
_controller.addListener(fetchAutocomplete);
}
@@ -55,7 +60,10 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SearchResults(restaurants: results)));
builder: (context) => SearchResults(
restaurants: results,
initialText: _controller.text,
)));
}
void hideSuggestions() {
@@ -151,10 +159,11 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(12),
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
child: TextFormField(
controller: _controller,
style: TextStyle(color: Colors.orange),
style: TextStyle(color: Colors.orange, fontSize: 14),
decoration: InputDecoration(
hintStyle: TextStyle(color: Colors.grey),
enabledBorder: OutlineInputBorder(

View File

@@ -8,12 +8,20 @@ import 'orderView.dart';
import 'favoritesView.dart';
import '../settings.dart';
class SearchResults extends StatelessWidget {
class SearchResults extends StatefulWidget {
SearchResults(
{Key key, @required this.initialText, @required this.restaurants})
: super(key: key);
final String initialText;
final List<Restaurant> restaurants;
final MenuiSettings settings = new MenuiSettings();
SearchResults({@required this.restaurants});
@override
_SearchResultsState createState() => _SearchResultsState();
}
class _SearchResultsState extends State<SearchResults> {
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -21,40 +29,34 @@ class SearchResults extends StatelessWidget {
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 30,
),
Image.asset(
"img/logo_orange.png",
width: 60,
),
MenuiSearchBar(),
Row(children: <Widget>[
Container(
padding: EdgeInsets.only(left: 12),
child: Text(
'Znaleziono: ${restaurants.length}',
style: TextStyle(color: Colors.grey),
decoration: BoxDecoration(color: Colors.grey[850]),
child: Column(
children: [
Container(
decoration: BoxDecoration(color: Colors.grey[900]),
child: MenuiSearchBar(widget.initialText)),
],
),
),
SizedBox(
height: 12,
),
)
]),
Expanded(
child: ListView.builder(
itemCount: restaurants.length,
itemCount: widget.restaurants.length,
itemBuilder: (context, index) {
return RestaurantCard(
restaurant: restaurants[index],
restaurant: widget.restaurants[index],
);
},
))
],
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: Container(
decoration: BoxDecoration(color: Colors.grey[900]),
@@ -87,12 +89,35 @@ class SearchResults extends StatelessWidget {
icon: Icons.settings,
text: "Ustawienia",
onPressed: () {
showSettings(context, settings);
showSettings(context, widget.settings);
},
),
],
),
),
appBar: AppBar(
title: Text(
'Znaleziono: ${widget.restaurants.length}',
style: TextStyle(
color: Colors.white, fontSize: 14, fontWeight: FontWeight.w400),
),
backgroundColor: Colors.grey[900],
leading: IconButton(
icon: Icon(
Icons.arrow_back_ios_rounded,
color: Colors.orange,
),
onPressed: () => Navigator.pop(context),
),
actions: [
MenuiButton(
color: Colors.grey,
icon: Icons.filter_alt_rounded,
text: "Filtruj",
onPressed: () {},
),
],
),
);
}
}

View File

@@ -138,8 +138,10 @@ class MenuiSettings {
Future<List<String>> getFavs() async {
final settings = await SharedPreferences.getInstance();
if (settings.containsKey('favorites')) {
return settings.getStringList('favorites');
final List<String> result = settings.getStringList('favorites');
return result;
} else {
print('Favorites Empty');
return [];
}
}