51 lines
1.2 KiB
Dart
51 lines
1.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:weather_icons/weather_icons.dart';
|
|
|
|
IconData weatherIcon(String icon) {
|
|
switch (icon) {
|
|
case "clear-day":
|
|
return WeatherIcons.day_sunny;
|
|
case "clear-night":
|
|
return WeatherIcons.night_clear;
|
|
case "partly-cloudy-day":
|
|
return WeatherIcons.day_sunny_overcast;
|
|
case "partly-cloudy-night":
|
|
return WeatherIcons.night_partly_cloudy;
|
|
case "cloudy":
|
|
return WeatherIcons.cloudy;
|
|
case "fog":
|
|
return WeatherIcons.fog;
|
|
case "wind":
|
|
return WeatherIcons.day_windy;
|
|
case "rain":
|
|
return WeatherIcons.day_rain;
|
|
case "sleet":
|
|
return WeatherIcons.day_sleet;
|
|
case "snow":
|
|
return WeatherIcons.day_snow;
|
|
case "hail":
|
|
return WeatherIcons.day_hail;
|
|
case "thunderstorm":
|
|
return WeatherIcons.day_thunderstorm;
|
|
default:
|
|
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);
|
|
}
|
|
}
|