Restaurant card | Settings button | Swiping | Redesigned folder structure
This commit is contained in:
74
lib/components/restaurantCard.dart
Normal file
74
lib/components/restaurantCard.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:menui_mobile/services.dart';
|
||||
|
||||
class RestaurantCard extends StatelessWidget {
|
||||
RestaurantCard({@required this.restaurant});
|
||||
|
||||
final Restaurant restaurant;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: ClipRRect(
|
||||
child: Image.network(
|
||||
restaurant.imgUrl,
|
||||
width: 80,
|
||||
height: 80,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
borderRadius: BorderRadius.all(Radius.circular(8)),
|
||||
),
|
||||
padding: EdgeInsets.all(8),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
restaurant.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: Colors.orange[600], fontSize: 16, height: 1.6),
|
||||
),
|
||||
Container(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'Miasto: ${restaurant.city}',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: Colors.grey, fontSize: 14),
|
||||
),
|
||||
Text(
|
||||
restaurant.description,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 2,
|
||||
style: TextStyle(color: Colors.grey, fontSize: 14),
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
)),
|
||||
Container(
|
||||
child: Icon(
|
||||
Icons.arrow_right,
|
||||
color: Colors.orange,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
color: Color.fromRGBO(50, 50, 50, 0.8),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
margin: EdgeInsets.symmetric(horizontal: 12),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:menui_mobile/main.dart';
|
||||
import '../services.dart';
|
||||
|
||||
class MenuiSearchBar extends StatefulWidget {
|
||||
@@ -18,32 +19,50 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
|
||||
var suggestions = <String>[];
|
||||
bool suggestionsOpen = false;
|
||||
|
||||
Future<void> fetchAutocomplete(text) async {
|
||||
final List<String> results = await services.fetchAutocomplete(text);
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller.addListener(fetchAutocomplete);
|
||||
}
|
||||
|
||||
setState(() {
|
||||
suggestions = results;
|
||||
});
|
||||
Future<void> fetchAutocomplete() async {
|
||||
if (_controller.text.isNotEmpty) {
|
||||
final List<String> results =
|
||||
await services.fetchAutocomplete(_controller.text);
|
||||
|
||||
if (!suggestionsOpen && results.isNotEmpty) {
|
||||
setState(() {
|
||||
suggestionsOpen = true;
|
||||
suggestions = results;
|
||||
});
|
||||
_overlayEntry = _createOverlayEntry();
|
||||
Overlay.of(context).insert(_overlayEntry);
|
||||
|
||||
if (!suggestionsOpen && results.isNotEmpty) {
|
||||
setState(() {
|
||||
suggestionsOpen = true;
|
||||
});
|
||||
_overlayEntry = _createOverlayEntry();
|
||||
Overlay.of(context).insert(_overlayEntry);
|
||||
} else if (results.isEmpty) {
|
||||
hideSuggestions();
|
||||
}
|
||||
print(suggestions);
|
||||
} else {
|
||||
hideSuggestions();
|
||||
}
|
||||
print(suggestions);
|
||||
}
|
||||
|
||||
Future<void> searchRestaurantsByString() async {
|
||||
final List<Restaurant> results =
|
||||
await services.fetchSearchByString(_controller.text);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SearchResults(restaurants: results)));
|
||||
}
|
||||
|
||||
void hideSuggestions() {
|
||||
if (suggestionsOpen) {
|
||||
_overlayEntry.remove();
|
||||
setState(() {
|
||||
suggestions = [];
|
||||
suggestionsOpen = false;
|
||||
});
|
||||
}
|
||||
@@ -82,6 +101,7 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
_controller.text = suggestions[index];
|
||||
searchRestaurantsByString();
|
||||
},
|
||||
title: Text(
|
||||
suggestions[index],
|
||||
@@ -115,7 +135,7 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: TextFormField(
|
||||
controller: _controller,
|
||||
onChanged: (text) => fetchAutocomplete(text),
|
||||
//onChanged: (text) => fetchAutocomplete(text),
|
||||
style: TextStyle(color: Colors.orange),
|
||||
decoration: InputDecoration(
|
||||
hintStyle: TextStyle(color: Colors.grey),
|
||||
|
||||
Reference in New Issue
Block a user