change suggestions list for input geo #31

Merged
v4l3n71n merged 1 commits from hotfix/refactor-input-tags into main 2024-12-30 20:55:34 +00:00
Showing only changes of commit b2e7080265 - Show all commits

View File

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