change suggestions list for input geo
This commit is contained in:
parent
d8b3bf7ca2
commit
b2e7080265
@ -46,7 +46,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
String itemName = '';
|
String itemName = '';
|
||||||
String itemTags = '';
|
String itemTags = '';
|
||||||
String query = '';
|
String query = '';
|
||||||
List<Map<String, dynamic>> suggestions = [];
|
List<Map<String, dynamic>> suggestionsGeo = [];
|
||||||
List<Map<String, dynamic>> suggestionsItem = [];
|
List<Map<String, dynamic>> suggestionsItem = [];
|
||||||
List<Map<String, dynamic>> suggestionsTags = [];
|
List<Map<String, dynamic>> suggestionsTags = [];
|
||||||
TextEditingController inputGeo = TextEditingController();
|
TextEditingController inputGeo = TextEditingController();
|
||||||
@ -249,7 +249,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> searchSuggestions(String input) async {
|
Future<void> searchSuggestionsGeo(String input) async {
|
||||||
await dotenv.load(fileName: ".env"); // Load .env file
|
await dotenv.load(fileName: ".env"); // Load .env file
|
||||||
|
|
||||||
final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? '';
|
final mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? '';
|
||||||
@ -260,14 +260,14 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final data = json.decode(response.body);
|
final data = json.decode(response.body);
|
||||||
setState(() {
|
setState(() {
|
||||||
suggestions = (data['features'] as List)
|
suggestionsGeo = (data['features'] as List)
|
||||||
.map((feature) => {
|
.map((feature) => {
|
||||||
'place_name': feature['place_name'],
|
'place_name': feature['place_name'],
|
||||||
'geometry': feature[
|
'geometry': feature[
|
||||||
'geometry'], // Include geometry for latitude/longitude
|
'geometry'], // Include geometry for latitude/longitude
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
if (suggestions.isNotEmpty) {
|
if (suggestionsGeo.isNotEmpty) {
|
||||||
showArrow = false;
|
showArrow = false;
|
||||||
showInputSearch = false;
|
showInputSearch = false;
|
||||||
showInputTag = false;
|
showInputTag = false;
|
||||||
@ -501,7 +501,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
inputGeo.clear(); // Clear the text field
|
inputGeo.clear(); // Clear the text field
|
||||||
geographicalZone =
|
geographicalZone =
|
||||||
''; // Reset the geographical zone state
|
''; // Reset the geographical zone state
|
||||||
suggestions.clear();
|
suggestionsGeo.clear();
|
||||||
showArrow = true;
|
showArrow = true;
|
||||||
showInputSearch =
|
showInputSearch =
|
||||||
true; // Optionally clear suggestions
|
true; // Optionally clear suggestions
|
||||||
@ -516,7 +516,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
if (value.isNotEmpty) {
|
if (value.isNotEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
geographicalZone = value;
|
geographicalZone = value;
|
||||||
searchSuggestions(value);
|
searchSuggestionsGeo(value);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
@ -525,7 +525,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
inputGeo.clear(); // Clear the text field
|
inputGeo.clear(); // Clear the text field
|
||||||
geographicalZone = ''; // Reset the geographical zone state
|
geographicalZone = ''; // Reset the geographical zone state
|
||||||
suggestions.clear(); // Optionally clear suggestions
|
suggestionsGeo.clear(); // Optionally clear suggestions
|
||||||
showArrow = true;
|
showArrow = true;
|
||||||
showInputSearch = true;
|
showInputSearch = true;
|
||||||
showInputTag = true;
|
showInputTag = true;
|
||||||
@ -536,7 +536,7 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (suggestions.isNotEmpty)
|
if (suggestionsGeo.isNotEmpty)
|
||||||
Container(
|
Container(
|
||||||
height: 200,
|
height: 200,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@ -545,20 +545,20 @@ class _MyHomePageState extends State<ListItemMenu> {
|
|||||||
),
|
),
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: suggestions.length,
|
itemCount: suggestionsGeo.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(suggestions[index]['place_name']),
|
title: Text(suggestionsGeo[index]['place_name']),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
final latitude =
|
final latitude =
|
||||||
suggestions[index]['geometry']['coordinates'][1];
|
suggestionsGeo[index]['geometry']['coordinates'][1];
|
||||||
final longitude =
|
final longitude =
|
||||||
suggestions[index]['geometry']['coordinates'][0];
|
suggestionsGeo[index]['geometry']['coordinates'][0];
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
geographicalZone = suggestions[index]['place_name'];
|
geographicalZone = suggestionsGeo[index]['place_name'];
|
||||||
inputGeo.text = geographicalZone;
|
inputGeo.text = geographicalZone;
|
||||||
suggestions.clear();
|
suggestionsGeo.clear();
|
||||||
showArrow = true;
|
showArrow = true;
|
||||||
showInputSearch = true;
|
showInputSearch = true;
|
||||||
showInputTag = true;
|
showInputTag = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user