add locations by search
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:wetter/models/location_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class OpenStreetMapAPI {
|
||||
static Future<List<LocationModel>> getLocationsFromSearch(
|
||||
String search) async {
|
||||
final response = await http.get(
|
||||
Uri.parse(
|
||||
'https://nominatim.openstreetmap.org/search.php?q=$search&format=jsonv2'),
|
||||
headers: {"Accept": "application/json"});
|
||||
if (response.statusCode == 200) {
|
||||
List<LocationModel> locations = [];
|
||||
List<dynamic> results = jsonDecode(response.body);
|
||||
for (Map<String, dynamic> result in results) {
|
||||
locations.add(LocationModel.fromJson(result));
|
||||
}
|
||||
return locations;
|
||||
} else {
|
||||
throw Exception('Failed to load weather data');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:weather_icons/weather_icons.dart';
|
||||
|
||||
@@ -31,3 +33,18 @@ IconData weatherIcon(String icon) {
|
||||
return WeatherIcons.alien;
|
||||
}
|
||||
}
|
||||
|
||||
class Debouncer {
|
||||
final int milliseconds;
|
||||
VoidCallback? action;
|
||||
Timer? _timer;
|
||||
|
||||
Debouncer({required this.milliseconds});
|
||||
|
||||
run(VoidCallback action) {
|
||||
if (_timer != null) {
|
||||
_timer!.cancel();
|
||||
}
|
||||
_timer = Timer(Duration(milliseconds: milliseconds), action);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user