Я использую будущего построителя, чтобы получить данные из снимка и отфильтровать эти данные в другую функцию Future, которая создает маркеры. Я получаю результаты от фильтрации местоположений для всех ресторанов, но функция постоянно обновляется, а данные просто мерцают.
Редактировать 2: JSON Данные
{ restaurant:[ {
"id": 4,
"restaurant_name": "Good Chemistry",
"phone": "1231231234",
"street_address": "2 Penn Plaza",
"restaurant_logo": "https://restaurants.s3.amazonaws.com/restaurant_logo/GOODCHEM-3-web_99314.jpg",
"restaurant_photo": "https://restaurants.s3.amazonaws.com/restaurant_photo/GOODCHEM-3-web_99314.jpg",
"city": "NY",
"state": "New York",
"zip_Code": 10010,
"lat": 40.8931283,
"lng": -73.8205375,
"latlng": "(40.7770112244898, -74.2110798163265)",
"opening_hours": [
{
"day_of_week": "Tuesday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Wednesday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Thursday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Friday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Saturday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Sunday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": 7,
"opening_time": "08:00:00",
"closing_time": "22:00:00"
}
],
"ratings": 4.1
},
{
"id": 3,
"restaurant_name": "The Farmacy",
"phone": "1231231234",
"street_address": "11 Penn Plaza",
"restaurant_logo": "https://restaurants.s3.amazonaws.com/restaurant_logo/farma.jpg",
"restaurant_photo": "https://restaurants.s3.amazonaws.com/restaurant_photo/farma.jpg",
"city": "NY",
"state": "New York",
"zip_Code": 10010,
"lat": 40.8931283,
"lng": -73.8205375,
"latlng": "(40.7770112244898, -74.2110798163265)",
"opening_hours": [
{
"day_of_week": "Tuesday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Wednesday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Thursday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Friday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Saturday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Sunday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": 7,
"opening_time": "08:00:00",
"closing_time": "22:00:00"
}
],
"ratings": 4.7
},
{
"id": 2,
"restaurant_name": "Hoboken Smokin",
"phone": "123-123-1234",
"street_address": "11 Penn Plaza",
"restaurant_logo": "https://restaurants.s3.amazonaws.com/restaurant_logo/urban-restaurant-web-1024x640.jpg",
"restaurant_photo": "https://restaurants.s3.amazonaws.com/restaurant_photo/urban-restaurant-web-1024x640.jpg",
"city": "NY",
"state": "New York",
"zip_Code": 10010,
"lat": 40.8931283,
"lng": -73.8205375,
"latlng": "(40.7770112244898, -74.2110798163265)",
"opening_hours": [
{
"day_of_week": "Tuesday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Wednesday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Thursday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Friday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Saturday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Sunday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": 7,
"opening_time": "08:00:00",
"closing_time": "22:00:00"
}
],
"ratings": 3.5
},
{
"id": 1,
"restaurant_name": "The Bakeree",
"phone": "1231231234",
"street_address": "433 5th Ave",
"restaurant_logo": "https://restaurants.s3.amazonaws.com/restaurant_logo/restaurantimage.jpeg",
"restaurant_photo": "https://restaurants.s3.amazonaws.com/restaurant_photo/restaurantimage.jpeg",
"city": "NY",
"state": "New York",
"zip_Code": 10016,
"lat": 40.7512061,
"lng": -73.9822721,
"latlng": "(40.7770112244898, -74.2110798163265)",
"opening_hours": [
{
"day_of_week": "Tuesday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Wednesday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Thursday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Friday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Saturday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": "Sunday",
"opening_time": "08:00:00",
"closing_time": "22:00:00"
},
{
"day_of_week": 7,
"opening_time": "08:00:00",
"closing_time": "22:00:00"
}
],
"ratings": 4.6
}
]
}
РЕДАКТ. 1: _setRestaurant function
Future getRestaurants() async {
var url = 'http://yellows-1929.herokuapp.com/api/customer/restaurant/';
var response = await http.get(url);
var responseData = json.decode(response.body);
Restaurants _restaurant = Restaurants.fromJSON(responseData);
return _restaurant.restaurant;
}
Filter Location function
<!-- begin snippet: js hide: false console: true babel: false -->
Будущий построитель, который получает данные и вызывает функцию filterMarker:
Widget _buildRestaurants() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
FutureBuilder(
future: _setRestaurants,
builder: (context, AsyncSnapshot snapshot) {
var restaurants = snapshot.data;
recRestaurants = snapshot.data;
if (snapshot.data == null) {
return Center(child: CircularProgressIndicator());
} else {
filterMarker(restaurants, 20);
return Column(
children: <Widget>[
_makeRestaurants(restaurants),
_buildCoupon(),
_buildVendors(filteredVenues)
],
);
}
})
]));
}
Фильтр просто постоянно обновляется и печатает
flutter: the lat is 41.722068434324785 and the long is -74.34910777767849
flutter: There are 1 _filteredMarkers
flutter: There are 0 _filteredMarkers
flutter: There are 0 _filteredMarkers
flutter: There are 1 _filteredMarkers
flutter: There are 1 _filteredMarkers
flutter: There are 1 _filteredMarkers
flutter: There are 0 _filteredMarkers
flutter: There are 0 _filteredMarkers
flutter: There are 1 _filteredMarkers