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,107 +1,102 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:menui_mobile/components/restaurantCardAsync.dart';
import '../settings.dart'; import '../settings.dart';
import 'homeScreen.dart'; import 'homeScreen.dart';
import 'orderView.dart'; import 'orderView.dart';
import 'menuiButton.dart'; import 'menuiButton.dart';
class FavoritesView extends StatelessWidget { class FavoritesView extends StatefulWidget {
final settings = new MenuiSettings(); 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: Container( body: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)), image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)),
child: Column( child: FutureBuilder(
children: <Widget>[ future: favorites,
Container( builder: (context, snapshot) {
decoration: BoxDecoration(color: Colors.grey[900]), if (snapshot.hasData) {
child: Column( List<String> result = snapshot.data;
children: [ return ListView.builder(
SizedBox( itemCount: result.length,
height: 20, itemBuilder: (context, index) {
), return RestaurantCardAsync(
Container( id: result[index],
decoration: BoxDecoration(color: Colors.grey[900]), );
child: Row( },
mainAxisAlignment: MainAxisAlignment.spaceBetween, );
children: [ } else {
RaisedButton( return null;
color: Colors.grey[900], }
elevation: 0,
padding:
EdgeInsets.symmetric(vertical: 12, horizontal: 4),
onPressed: () {
Navigator.pop(context);
},
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: [],
)
],
),
)
],
),
),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: Container(
decoration: BoxDecoration(color: Colors.grey[900]),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
MenuiButton(
color: Colors.orange,
icon: Icons.home_rounded,
text: "Szukaj",
onPressed: () => Navigator.push(
context, MaterialPageRoute(builder: (context) => HomePage())),
),
MenuiButton(
color: Colors.orange,
icon: Icons.note_rounded,
text: "Zamównienie",
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => OrderView())),
),
MenuiButton(
color: Colors.orange,
icon: Icons.favorite_rounded,
text: "Ulubione",
onPressed: () {},
),
MenuiButton(
color: Colors.orange,
icon: Icons.settings,
text: "Ustawienia",
onPressed: () {
showSettings(context, settings);
}, },
), )),
], floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: Container(
decoration: BoxDecoration(color: Colors.grey[900]),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
MenuiButton(
color: Colors.orange,
icon: Icons.home_rounded,
text: "Szukaj",
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => HomePage())),
),
MenuiButton(
color: Colors.orange,
icon: Icons.note_rounded,
text: "Zamównienie",
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => OrderView())),
),
MenuiButton(
color: Colors.orange,
icon: Icons.favorite_rounded,
text: "Ulubione",
onPressed: () {},
),
MenuiButton(
color: Colors.orange,
icon: Icons.settings,
text: "Ustawienia",
onPressed: () {
showSettings(context, settings);
},
),
],
),
), ),
), 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", "img/logo_orange.png",
width: 160, width: 160,
), ),
MenuiSearchBar(), MenuiSearchBar(''),
Text( Text(
'lub', 'lub',
style: TextStyle(color: Colors.grey[500]), style: TextStyle(color: Colors.grey[500]),

View File

@@ -10,104 +10,92 @@ class OrderView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: Container( body: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)), image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Container( Container(
decoration: BoxDecoration(color: Colors.grey[850]), decoration: BoxDecoration(color: Colors.grey[800]),
child: Column( child: Row(
children: [ mainAxisAlignment: MainAxisAlignment.center,
SizedBox( children: [
height: 20, Icon(
), Icons.attach_money_rounded,
Container( color: Colors.orange,
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,
),
],
)
],
), ),
), Text(
Container( 'Suma: 0zł',
decoration: BoxDecoration(color: Colors.grey[800]), style: TextStyle(color: Colors.white, fontSize: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.attach_money_rounded,
color: Colors.orange,
),
Text(
'Suma: 0zł',
style: TextStyle(color: Colors.white, fontSize: 12),
),
],
), ),
) ],
], ),
)
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: Container(
decoration: BoxDecoration(color: Colors.grey[900]),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
MenuiButton(
color: Colors.orange,
icon: Icons.home_rounded,
text: "Szukaj",
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => HomePage())),
), ),
), MenuiButton(
], color: Colors.orange,
icon: Icons.note_rounded,
text: "Zamównienie",
onPressed: () {},
),
MenuiButton(
color: Colors.orange,
icon: Icons.favorite_rounded,
text: "Ulubione",
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => FavoritesView())),
),
MenuiButton(
color: Colors.orange,
icon: Icons.settings,
text: "Ustawienia",
onPressed: () {
showSettings(context, settings);
},
),
],
),
), ),
), appBar: AppBar(
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, title: Text(
floatingActionButton: Container( 'Zamówienie',
decoration: BoxDecoration(color: Colors.grey[900]), style: TextStyle(
child: Row( color: Colors.white, fontWeight: FontWeight.w400, fontSize: 14),
mainAxisAlignment: MainAxisAlignment.center, ),
children: <Widget>[ backgroundColor: Colors.grey[900],
MenuiButton( leading: IconButton(
icon: Icon(
Icons.arrow_back_ios_rounded,
color: Colors.orange, color: Colors.orange,
icon: Icons.home_rounded,
text: "Szukaj",
onPressed: () => Navigator.push(
context, MaterialPageRoute(builder: (context) => HomePage())),
), ),
onPressed: () => Navigator.pop(context),
),
actions: [
MenuiButton( MenuiButton(
color: Colors.orange, color: Colors.orange,
icon: Icons.note_rounded,
text: "Zamównienie",
onPressed: () {},
),
MenuiButton(
color: Colors.orange,
icon: Icons.favorite_rounded,
text: "Ulubione",
onPressed: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => FavoritesView())),
),
MenuiButton(
color: Colors.orange,
icon: Icons.settings,
text: "Ustawienia",
onPressed: () { onPressed: () {
showSettings(context, settings); 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'; import 'searchResults.dart';
class MenuiSearchBar extends StatefulWidget { class MenuiSearchBar extends StatefulWidget {
final String initialValue;
MenuiSearchBar(this.initialValue);
@override @override
MenuiSearchBarState createState() { MenuiSearchBarState createState() {
return MenuiSearchBarState(); return MenuiSearchBarState();
@@ -23,6 +27,7 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_controller.text = widget.initialValue;
_controller.addListener(fetchAutocomplete); _controller.addListener(fetchAutocomplete);
} }
@@ -55,7 +60,10 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => SearchResults(restaurants: results))); builder: (context) => SearchResults(
restaurants: results,
initialText: _controller.text,
)));
} }
void hideSuggestions() { void hideSuggestions() {
@@ -151,10 +159,11 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
Padding( Padding(
padding: const EdgeInsets.all(12), padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
child: TextFormField( child: TextFormField(
controller: _controller, controller: _controller,
style: TextStyle(color: Colors.orange), style: TextStyle(color: Colors.orange, fontSize: 14),
decoration: InputDecoration( decoration: InputDecoration(
hintStyle: TextStyle(color: Colors.grey), hintStyle: TextStyle(color: Colors.grey),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(

View File

@@ -8,12 +8,20 @@ import 'orderView.dart';
import 'favoritesView.dart'; import 'favoritesView.dart';
import '../settings.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 List<Restaurant> restaurants;
final MenuiSettings settings = new MenuiSettings(); final MenuiSettings settings = new MenuiSettings();
SearchResults({@required this.restaurants}); @override
_SearchResultsState createState() => _SearchResultsState();
}
class _SearchResultsState extends State<SearchResults> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@@ -21,38 +29,32 @@ class SearchResults extends StatelessWidget {
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)), image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)),
child: Center( child: Column(
child: Column( mainAxisAlignment: MainAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[
children: <Widget>[ Container(
SizedBox( decoration: BoxDecoration(color: Colors.grey[850]),
height: 30, child: Column(
children: [
Container(
decoration: BoxDecoration(color: Colors.grey[900]),
child: MenuiSearchBar(widget.initialText)),
],
), ),
Image.asset( ),
"img/logo_orange.png", SizedBox(
width: 60, height: 12,
), ),
MenuiSearchBar(), Expanded(
Row(children: <Widget>[ child: ListView.builder(
Container( itemCount: widget.restaurants.length,
padding: EdgeInsets.only(left: 12), itemBuilder: (context, index) {
child: Text( return RestaurantCard(
'Znaleziono: ${restaurants.length}', restaurant: widget.restaurants[index],
style: TextStyle(color: Colors.grey), );
), },
) ))
]), ],
Expanded(
child: ListView.builder(
itemCount: restaurants.length,
itemBuilder: (context, index) {
return RestaurantCard(
restaurant: restaurants[index],
);
},
))
],
),
), ),
), ),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
@@ -87,12 +89,35 @@ class SearchResults extends StatelessWidget {
icon: Icons.settings, icon: Icons.settings,
text: "Ustawienia", text: "Ustawienia",
onPressed: () { 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 { Future<List<String>> getFavs() async {
final settings = await SharedPreferences.getInstance(); final settings = await SharedPreferences.getInstance();
if (settings.containsKey('favorites')) { if (settings.containsKey('favorites')) {
return settings.getStringList('favorites'); final List<String> result = settings.getStringList('favorites');
return result;
} else { } else {
print('Favorites Empty');
return []; return [];
} }
} }