Advertisement
namo352

weather_repository_impl.dart

Jul 30th, 2024
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 1.19 KB | None | 0 0
  1. import 'package:dio/dio.dart';
  2. import 'package:ementodo/core/resources/data_state.dart';
  3. import 'package:ementodo/features/feature_weather/data/data_sources/remote/api_provider.dart';
  4. import 'package:ementodo/features/feature_weather/data/models/current_city_model.dart';
  5. import 'package:ementodo/features/feature_weather/domain/entities/current_city_entity.dart';
  6. import 'package:ementodo/features/feature_weather/domain/repositories/weather_repository.dart';
  7.  
  8. class WeatherRepositoryImpl extends WeatherRepository {
  9.   ApiProvider apiProvider;
  10.  
  11.   WeatherRepositoryImpl(this.apiProvider);
  12.  
  13.   @override
  14.   Future<DataState<CurrentCityEntity>> fetchCurrentWeatherData(String cityName)
  15.   async {
  16.     try {
  17.       Response response = await apiProvider.callCurrentWeather(cityName);
  18.       if (response.statusCode == 200) {
  19.         CurrentCityEntity currentCityEntity =
  20.             CurrentCityModel.fromJson(response.data);
  21.  
  22.         return DataSuccess(currentCityEntity);
  23.       } else {
  24.         DataField("Something went wrong. Try again...");
  25.       }
  26.     } catch (e) {
  27.       DataField("Please check your connection...");
  28.     }
  29.     return DataField("Something went wrong. Try again...");
  30.   }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement