fixes
This commit is contained in:
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||||
import '../services.dart';
|
import '../services.dart';
|
||||||
import 'package:geolocator/geolocator.dart';
|
import 'package:geolocator/geolocator.dart';
|
||||||
|
import 'restaurantView.dart';
|
||||||
|
|
||||||
class MapView extends StatefulWidget {
|
class MapView extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@@ -30,6 +31,11 @@ class MapViewState extends State<MapView> {
|
|||||||
position: LatLng(
|
position: LatLng(
|
||||||
thisRestaurant.coordinates[0], thisRestaurant.coordinates[1]),
|
thisRestaurant.coordinates[0], thisRestaurant.coordinates[1]),
|
||||||
infoWindow: InfoWindow(
|
infoWindow: InfoWindow(
|
||||||
|
onTap: () => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
RestaurantView(id: thisRestaurant.id))),
|
||||||
title: '${thisRestaurant.name}',
|
title: '${thisRestaurant.name}',
|
||||||
snippet: 'Kuchnia: ${thisRestaurant.type}'));
|
snippet: 'Kuchnia: ${thisRestaurant.type}'));
|
||||||
markers[markerId] = marker;
|
markers[markerId] = marker;
|
||||||
@@ -65,7 +71,7 @@ class MapViewState extends State<MapView> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [Text("error...")],
|
children: [Text("Błąd...")],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -81,7 +87,7 @@ class MapViewState extends State<MapView> {
|
|||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(top: 16),
|
padding: EdgeInsets.only(top: 16),
|
||||||
child: Text('Awaiting result...'),
|
child: Text('Szukam restauracji...'),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
|
|||||||
final _controller = TextEditingController();
|
final _controller = TextEditingController();
|
||||||
String previousText = '';
|
String previousText = '';
|
||||||
|
|
||||||
var suggestions = <String>[];
|
MenuiSuggestions suggestions;
|
||||||
bool suggestionsOpen = false;
|
bool suggestionsOpen = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -29,20 +29,19 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
|
|||||||
Future<void> fetchAutocomplete() async {
|
Future<void> fetchAutocomplete() async {
|
||||||
if (_controller.text.isNotEmpty && _controller.text != previousText) {
|
if (_controller.text.isNotEmpty && _controller.text != previousText) {
|
||||||
previousText = _controller.text;
|
previousText = _controller.text;
|
||||||
final List<String> results =
|
final MenuiSuggestions results =
|
||||||
await services.fetchAutocomplete(_controller.text);
|
await services.fetchAutocomplete(_controller.text);
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
suggestions = results;
|
suggestions = results;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!suggestionsOpen && results.isNotEmpty) {
|
if (!suggestionsOpen && !results.suggestionsEmpty()) {
|
||||||
setState(() {
|
setState(() {
|
||||||
suggestionsOpen = true;
|
suggestionsOpen = true;
|
||||||
});
|
});
|
||||||
_overlayEntry = _createOverlayEntry();
|
_overlayEntry = _createOverlayEntry();
|
||||||
Overlay.of(context).insert(_overlayEntry);
|
Overlay.of(context).insert(_overlayEntry);
|
||||||
} else if (results.isEmpty) {
|
} else if (results.suggestionsEmpty()) {
|
||||||
hideSuggestions();
|
hideSuggestions();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -63,7 +62,7 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
|
|||||||
if (suggestionsOpen) {
|
if (suggestionsOpen) {
|
||||||
_overlayEntry.remove();
|
_overlayEntry.remove();
|
||||||
setState(() {
|
setState(() {
|
||||||
suggestions = [];
|
suggestions = new MenuiSuggestions.empty();
|
||||||
suggestionsOpen = false;
|
suggestionsOpen = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -102,19 +101,29 @@ class MenuiSearchBarState extends State<MenuiSearchBar> {
|
|||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: suggestions.length,
|
itemCount: suggestions.getLenght(),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_controller.text = suggestions[index];
|
_controller.text =
|
||||||
|
suggestions.getSuggestion(index);
|
||||||
searchRestaurantsByString();
|
searchRestaurantsByString();
|
||||||
},
|
},
|
||||||
leading: Icon(
|
leading: (() {
|
||||||
Icons.search_rounded,
|
if (suggestions.isCity(index)) {
|
||||||
color: Colors.grey,
|
return Icon(
|
||||||
),
|
Icons.location_city_rounded,
|
||||||
|
color: Colors.grey,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return Icon(
|
||||||
|
Icons.fastfood_rounded,
|
||||||
|
color: Colors.grey,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}()),
|
||||||
title: Text(
|
title: Text(
|
||||||
suggestions[index],
|
suggestions.getSuggestion(index),
|
||||||
style: TextStyle(color: Colors.grey),
|
style: TextStyle(color: Colors.grey),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class MenuiServices {
|
|||||||
final String backendURL = 'https://api.menui.pl/';
|
final String backendURL = 'https://api.menui.pl/';
|
||||||
final MenuiSettings settings = new MenuiSettings();
|
final MenuiSettings settings = new MenuiSettings();
|
||||||
|
|
||||||
Future<List<String>> fetchAutocomplete(String text) async {
|
Future<MenuiSuggestions> fetchAutocomplete(String text) async {
|
||||||
final response =
|
final response =
|
||||||
await http.get('${backendURL}search/autocomplete?string=$text');
|
await http.get('${backendURL}search/autocomplete?string=$text');
|
||||||
if (response.statusCode == 200 || response.statusCode == 304) {
|
if (response.statusCode == 200 || response.statusCode == 304) {
|
||||||
@@ -17,12 +17,11 @@ class MenuiServices {
|
|||||||
final List<String> cities = citiesDynamic.cast<String>().toList();
|
final List<String> cities = citiesDynamic.cast<String>().toList();
|
||||||
final List<String> restaurants =
|
final List<String> restaurants =
|
||||||
restaurantsDynamic.cast<String>().toList();
|
restaurantsDynamic.cast<String>().toList();
|
||||||
final List<String> result = [...cities, ...restaurants];
|
final MenuiSuggestions result =
|
||||||
|
new MenuiSuggestions(cities: cities, names: restaurants);
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
print("coś tu nie zagrało podczas pobierania sugestii");
|
return new MenuiSuggestions(cities: [], names: []);
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,3 +459,39 @@ class MarkersAndLocation {
|
|||||||
|
|
||||||
MarkersAndLocation({@required this.markers, @required this.coordinates});
|
MarkersAndLocation({@required this.markers, @required this.coordinates});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MenuiSuggestions {
|
||||||
|
final List<String> cities;
|
||||||
|
final List<String> names;
|
||||||
|
|
||||||
|
MenuiSuggestions({@required this.cities, @required this.names});
|
||||||
|
|
||||||
|
MenuiSuggestions.empty({this.cities = const [], this.names = const []});
|
||||||
|
|
||||||
|
bool suggestionsEmpty() {
|
||||||
|
if (this.cities.isEmpty && this.names.isEmpty) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int getLenght() {
|
||||||
|
int lenght = this.cities.length + this.names.length;
|
||||||
|
return lenght;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getSuggestion(int index) {
|
||||||
|
List<String> suggestions = new List<String>.from(this.cities)
|
||||||
|
..addAll(this.names);
|
||||||
|
return suggestions[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isCity(int index) {
|
||||||
|
if (index > (this.cities.length - 1)) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user