diff --git a/lib/components/favoritesView.dart b/lib/components/favoritesView.dart index f882ff2..50dea12 100644 --- a/lib/components/favoritesView.dart +++ b/lib/components/favoritesView.dart @@ -1,107 +1,102 @@ 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 { + final MenuiSettings settings = new MenuiSettings(); + Future> favorites; + + @override + void initState() { + super.initState(); + favorites = settings.getFavs(); + } @override Widget build(BuildContext context) { return Scaffold( - body: Container( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)), - child: Column( - children: [ - 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: Column( - mainAxisSize: MainAxisSize.min, - children: [ - 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: [ - 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); + body: Container( + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)), + child: FutureBuilder( + future: favorites, + builder: (context, snapshot) { + if (snapshot.hasData) { + List result = snapshot.data; + return ListView.builder( + itemCount: result.length, + itemBuilder: (context, index) { + return RestaurantCardAsync( + id: result[index], + ); + }, + ); + } else { + return null; + } }, - ), - ], + )), + floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, + floatingActionButton: Container( + decoration: BoxDecoration(color: Colors.grey[900]), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + 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), + ), + )); } } diff --git a/lib/components/homeScreen.dart b/lib/components/homeScreen.dart index ee4d6b7..7b1a4dd 100644 --- a/lib/components/homeScreen.dart +++ b/lib/components/homeScreen.dart @@ -24,7 +24,7 @@ class HomePage extends StatelessWidget { "img/logo_orange.png", width: 160, ), - MenuiSearchBar(), + MenuiSearchBar(''), Text( 'lub', style: TextStyle(color: Colors.grey[500]), diff --git a/lib/components/orderView.dart b/lib/components/orderView.dart index 3afc70b..bafc563 100644 --- a/lib/components/orderView.dart +++ b/lib/components/orderView.dart @@ -10,104 +10,92 @@ class OrderView extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - body: Container( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)), - child: Column( - children: [ - 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, - ), - ], - ) - ], + body: Container( + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage("img/bg_tile.jpg"), fit: BoxFit.cover)), + child: Column( + children: [ + Container( + decoration: BoxDecoration(color: Colors.grey[800]), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + Icons.attach_money_rounded, + color: Colors.orange, ), - ), - Container( - decoration: BoxDecoration(color: Colors.grey[800]), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon( - Icons.attach_money_rounded, - color: Colors.orange, - ), - Text( - 'Suma: 0zł', - style: TextStyle(color: Colors.white, fontSize: 12), - ), - ], + 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: [ + 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); + }, + ), + ], + ), ), - ), - floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - floatingActionButton: Container( - decoration: BoxDecoration(color: Colors.grey[900]), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - MenuiButton( + 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, - icon: Icons.home_rounded, - text: "Szukaj", - onPressed: () => Navigator.push( - context, MaterialPageRoute(builder: (context) => HomePage())), ), + onPressed: () => Navigator.pop(context), + ), + actions: [ 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); + settings.clearOrder(); }, + text: "Wyczyść", + icon: Icons.delete_forever_rounded, ), ], - ), - ), - ); + )); } } diff --git a/lib/components/restaurantCardAsync.dart b/lib/components/restaurantCardAsync.dart new file mode 100644 index 0000000..647446f --- /dev/null +++ b/lib/components/restaurantCardAsync.dart @@ -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: [ + 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: [ + 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: [ + 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: [ + 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: [ + 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), + ), + ); + } +} diff --git a/lib/components/searchBar.dart b/lib/components/searchBar.dart index f377795..668bdf8 100644 --- a/lib/components/searchBar.dart +++ b/lib/components/searchBar.dart @@ -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 { @override void initState() { super.initState(); + _controller.text = widget.initialValue; _controller.addListener(fetchAutocomplete); } @@ -55,7 +60,10 @@ class MenuiSearchBarState extends State { 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 { child: Column( children: [ 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( diff --git a/lib/components/searchResults.dart b/lib/components/searchResults.dart index b9bb88d..680b691 100644 --- a/lib/components/searchResults.dart +++ b/lib/components/searchResults.dart @@ -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 restaurants; final MenuiSettings settings = new MenuiSettings(); - SearchResults({@required this.restaurants}); + @override + _SearchResultsState createState() => _SearchResultsState(); +} +class _SearchResultsState extends State { @override Widget build(BuildContext context) { return Scaffold( @@ -21,38 +29,32 @@ 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: [ - SizedBox( - height: 30, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Container( + decoration: BoxDecoration(color: Colors.grey[850]), + child: Column( + children: [ + Container( + decoration: BoxDecoration(color: Colors.grey[900]), + child: MenuiSearchBar(widget.initialText)), + ], ), - Image.asset( - "img/logo_orange.png", - width: 60, - ), - MenuiSearchBar(), - Row(children: [ - Container( - padding: EdgeInsets.only(left: 12), - child: Text( - 'Znaleziono: ${restaurants.length}', - style: TextStyle(color: Colors.grey), - ), - ) - ]), - Expanded( - child: ListView.builder( - itemCount: restaurants.length, - itemBuilder: (context, index) { - return RestaurantCard( - restaurant: restaurants[index], - ); - }, - )) - ], - ), + ), + SizedBox( + height: 12, + ), + Expanded( + child: ListView.builder( + itemCount: widget.restaurants.length, + itemBuilder: (context, index) { + return RestaurantCard( + restaurant: widget.restaurants[index], + ); + }, + )) + ], ), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, @@ -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: () {}, + ), + ], + ), ); } } diff --git a/lib/settings.dart b/lib/settings.dart index 5571462..76ae242 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -138,8 +138,10 @@ class MenuiSettings { Future> getFavs() async { final settings = await SharedPreferences.getInstance(); if (settings.containsKey('favorites')) { - return settings.getStringList('favorites'); + final List result = settings.getStringList('favorites'); + return result; } else { + print('Favorites Empty'); return []; } }