This commit is contained in:
2020-12-27 16:22:44 +01:00
parent 7ce7a9205d
commit 223feb8c5c
3 changed files with 70 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import '../services.dart';
import 'package:geolocator/geolocator.dart';
import 'restaurantView.dart';
class MapView extends StatefulWidget {
@override
@@ -30,6 +31,11 @@ class MapViewState extends State<MapView> {
position: LatLng(
thisRestaurant.coordinates[0], thisRestaurant.coordinates[1]),
infoWindow: InfoWindow(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
RestaurantView(id: thisRestaurant.id))),
title: '${thisRestaurant.name}',
snippet: 'Kuchnia: ${thisRestaurant.type}'));
markers[markerId] = marker;
@@ -65,7 +71,7 @@ class MapViewState extends State<MapView> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [Text("error...")],
children: [Text("Błąd...")],
),
);
} else {
@@ -81,7 +87,7 @@ class MapViewState extends State<MapView> {
),
Padding(
padding: EdgeInsets.only(top: 16),
child: Text('Awaiting result...'),
child: Text('Szukam restauracji...'),
)
],
),

View File

@@ -17,7 +17,7 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
final _controller = TextEditingController();
String previousText = '';
var suggestions = <String>[];
MenuiSuggestions suggestions;
bool suggestionsOpen = false;
@override
@@ -29,20 +29,19 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
Future<void> fetchAutocomplete() async {
if (_controller.text.isNotEmpty && _controller.text != previousText) {
previousText = _controller.text;
final List<String> results =
final MenuiSuggestions results =
await services.fetchAutocomplete(_controller.text);
setState(() {
suggestions = results;
});
if (!suggestionsOpen && results.isNotEmpty) {
if (!suggestionsOpen && !results.suggestionsEmpty()) {
setState(() {
suggestionsOpen = true;
});
_overlayEntry = _createOverlayEntry();
Overlay.of(context).insert(_overlayEntry);
} else if (results.isEmpty) {
} else if (results.suggestionsEmpty()) {
hideSuggestions();
}
} else {
@@ -63,7 +62,7 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
if (suggestionsOpen) {
_overlayEntry.remove();
setState(() {
suggestions = [];
suggestions = new MenuiSuggestions.empty();
suggestionsOpen = false;
});
}
@@ -102,19 +101,29 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
child: ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: suggestions.length,
itemCount: suggestions.getLenght(),
itemBuilder: (context, index) {
return ListTile(
onTap: () {
_controller.text = suggestions[index];
_controller.text =
suggestions.getSuggestion(index);
searchRestaurantsByString();
},
leading: Icon(
Icons.search_rounded,
color: Colors.grey,
),
leading: (() {
if (suggestions.isCity(index)) {
return Icon(
Icons.location_city_rounded,
color: Colors.grey,
);
} else {
return Icon(
Icons.fastfood_rounded,
color: Colors.grey,
);
}
}()),
title: Text(
suggestions[index],
suggestions.getSuggestion(index),
style: TextStyle(color: Colors.grey),
),
);