open_weather_example_flutter
OpenWeatherMap API를 사용한 Flutter 날씨 앱 예제
- 스타
- 311
- 포크
- 74
- 최근 푸시(UTC)
- 2024. 4. 19.
- 프로젝트 상태
- 활성
원본 README
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Flutter Weather App Example
An example Flutter weather app using the OpenWeatherMap API.
Related Tutorials
Supported Features
- [x] Current weather (condition and temperature)
- [x] 5-day weather forecast
- [x] Search by city
App Architecture
The app is composed by three main layers.
Data Layer
The data layer contains a single HttpWeatherRepository that is used to fetch weather data from the OpenWeatherMap API.
The data is then parsed (using Freezed) and returned using type-safe entity classes (Weather and Forecast).
For more info about this, read this tutorial:
For more info about the project structure, read this:
Application Layer
This contains some providers that are used to fetch and cache the data from the HttpWeatherRepository.
// current city stored in the search box in the UI
final cityProvider = StateProvider<String>((ref) {
return 'London';
});
// provider to fetch the current weather
final currentWeatherProvider =
FutureProvider.autoDispose<WeatherData>((ref) async {
final city = ref.watch(cityProvider);
final weather =
await ref.watch(weatherRepositoryProvider).getWeather(city: city);
return WeatherData.from(weather);
});
// provider to fetch the hourly weather
final hourlyWeatherProvider =
FutureProvider.autoDispose<ForecastData>((ref) async {
final city = ref.watch(cityProvider);
final forecast =
await ref.watch(weatherRepositoryProvider).getForecast(city: city);
return ForecastData.from(forecast);
});
Presentation Layer
This layer holds all the widgets, which fetch the data from the FutureProviders above and map the resulting AsyncValue objects to the appropriate UI states (data, loading, error).
Packages in use
- riverpod for state management
- freezed for code generation
- http for talking to the REST API
- cached_network_image for caching images
- mocktail for testing
About the OpenStreetMap weather API
The app shows data from the following endpoints:
Note: to use the API you'll need to register an account and obtain your own API key. This can be set via --dart-define or inside lib/src/api/api_keys.dart.
LICENSE: MIT
분류
사용 중인 의존성
의존성 목록 14 개
- cached_network_image
^3.3.0 - cupertino_icons
^1.0.6 - flutter
{"sdk":"flutter"} - flutter_riverpod
^2.4.8 - freezed_annotation
^2.4.1 - http
^0.13.6 - intl
^0.18.1 - json_annotation
^4.8.1 - build_runner개발 의존성
^2.4.6 - flutter_test개발 의존성
{"sdk":"flutter"} - freezed개발 의존성
^2.4.5 - json_serializable개발 의존성
^6.7.1 - mocktail개발 의존성
^1.0.1 - flutter_lints개발 의존성
^3.0.1
순위
프로젝트에 맞는 저장소를 선택하려면?
사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.
- 이름, 작성자 또는 설명으로 검색하고 기술 주제로 범위를 좁힙니다.
- 스타, 포크, 최근 푸시를 함께 비교하세요. 스타는 관심의 지표이며 품질을 보장하지 않습니다.
- 사용하기 전에 GitHub에서 README, 라이선스, Issues를 확인하세요.
출처 및 관리
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗