Skip to content

Commit

Permalink
updated dart.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Avadhkumar-geek committed Sep 24, 2023
1 parent 127cab0 commit d7d0b99
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
channel: "stable"
- run: flutter doctor
- run: flutter pub get
- run: dart format --set-exit-if-changed .
- run: dart format --set-exit-if-changed -l 100 lib -l 100 example
- run: flutter analyze lib
- run: flutter test --no-pub --coverage

Expand Down
28 changes: 9 additions & 19 deletions lib/data/dataproviders/accuweather_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class AccuWeatherAPI {
static const String _baseUrl = "dataservice.accuweather.com";

static Future<List<LocationModel>> getLocation(String query) async {
final locationRequest = Uri.https(_baseUrl,
'/locations/v1/cities/autocomplete', {"q": query, "apikey": apiKey});
final locationRequest =
Uri.https(_baseUrl, '/locations/v1/cities/autocomplete', {"q": query, "apikey": apiKey});

final locationResponse = await http.get(locationRequest);

Expand All @@ -23,17 +23,14 @@ class AccuWeatherAPI {

final locationJson = jsonDecode(locationResponse.body) as List;

final locationList =
locationJson.map((e) => LocationModel.fromJson(e)).toList();
final locationList = locationJson.map((e) => LocationModel.fromJson(e)).toList();

return locationList;
}

static Future<WeatherModel> getWeatherData(int cityCode) async {
final weatherRequest = Uri.https(
_baseUrl,
'/currentconditions/v1/$cityCode',
{"apikey": apiKey, "details": "true"});
_baseUrl, '/currentconditions/v1/$cityCode', {"apikey": apiKey, "details": "true"});

final weatherResponse = await http.get(weatherRequest);

Expand All @@ -50,9 +47,7 @@ class AccuWeatherAPI {
}

static Future<ForecastModel> getForecastData(int cityCode) async {
final forecastRequest = Uri.https(
_baseUrl,
'/forecasts/v1/daily/5day/$cityCode',
final forecastRequest = Uri.https(_baseUrl, '/forecasts/v1/daily/5day/$cityCode',
{"apikey": apiKey, "details": "true", "metric": "true"});

final forecastResponse = await http.get(forecastRequest);
Expand All @@ -61,19 +56,15 @@ class AccuWeatherAPI {
throw 'No data available';
}

final forecastJson =
jsonDecode(forecastResponse.body) as Map<String, dynamic>;
final forecastJson = jsonDecode(forecastResponse.body) as Map<String, dynamic>;

final forecastData = ForecastModel.fromJson(forecastJson);

return forecastData;
}

static Future<int> getGeoPositionnKey(
double latitude, double longitude) async {
final positionRequest = Uri.https(
_baseUrl,
'/locations/v1/cities/geoposition/search',
static Future<int> getGeoPositionnKey(double latitude, double longitude) async {
final positionRequest = Uri.https(_baseUrl, '/locations/v1/cities/geoposition/search',
{"apikey": apiKey, "q": "$latitude,$longitude"});

final positionResponse = await http.get(positionRequest);
Expand All @@ -82,8 +73,7 @@ class AccuWeatherAPI {
throw 'No data available';
}

final positionJson =
jsonDecode(positionResponse.body) as Map<String, dynamic>;
final positionJson = jsonDecode(positionResponse.body) as Map<String, dynamic>;

final positionData = GeoPositionKeyModel.fromJson(positionJson);

Expand Down
22 changes: 6 additions & 16 deletions lib/data/models/forecast_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ class ForecastModel {
ForecastModel({this.headline, this.dailyForecasts});

ForecastModel.fromJson(Map<String, dynamic> json) {
headline =
json['Headline'] != null ? Headline.fromJson(json['Headline']) : null;
headline = json['Headline'] != null ? Headline.fromJson(json['Headline']) : null;
if (json['DailyForecasts'] != null) {
dailyForecasts = <DailyForecasts>[];
json['DailyForecasts'].forEach((v) {
Expand Down Expand Up @@ -90,9 +89,7 @@ class DailyForecasts {
date = json['Date'];
epochDate = json['EpochDate'];
sun = json['Sun'] != null ? Sun.fromJson(json['Sun']) : null;
temperature = json['Temperature'] != null
? Temperature.fromJson(json['Temperature'])
: null;
temperature = json['Temperature'] != null ? Temperature.fromJson(json['Temperature']) : null;
if (json['AirAndPollen'] != null) {
airAndPollen = <AirAndPollen>[];
json['AirAndPollen'].forEach((v) {
Expand Down Expand Up @@ -156,10 +153,8 @@ class Temperature {
Temperature({this.minimum, this.maximum});

Temperature.fromJson(Map<String, dynamic> json) {
minimum =
json['Minimum'] != null ? Minimum.fromJson(json['Minimum']) : null;
maximum =
json['Maximum'] != null ? Minimum.fromJson(json['Maximum']) : null;
minimum = json['Minimum'] != null ? Minimum.fromJson(json['Minimum']) : null;
maximum = json['Maximum'] != null ? Minimum.fromJson(json['Maximum']) : null;
}

Map<String, dynamic> toJson() {
Expand Down Expand Up @@ -203,8 +198,7 @@ class AirAndPollen {
int? categoryValue;
String? type;

AirAndPollen(
{this.name, this.value, this.category, this.categoryValue, this.type});
AirAndPollen({this.name, this.value, this.category, this.categoryValue, this.type});

AirAndPollen.fromJson(Map<String, dynamic> json) {
name = json['Name'];
Expand All @@ -231,11 +225,7 @@ class Day {
bool? hasPrecipitation;
String? precipitationType;

Day(
{this.icon,
this.iconPhrase,
this.hasPrecipitation,
this.precipitationType});
Day({this.icon, this.iconPhrase, this.hasPrecipitation, this.precipitationType});

Day.fromJson(Map<String, dynamic> json) {
icon = json['Icon'];
Expand Down
12 changes: 2 additions & 10 deletions lib/data/models/geolocation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,11 @@ class GeolocationModel {
String? country;
String? state;

GeolocationModel(
{this.name,
this.localNames,
this.lat,
this.lon,
this.country,
this.state});
GeolocationModel({this.name, this.localNames, this.lat, this.lon, this.country, this.state});

GeolocationModel.fromJson(Map<String, dynamic> json) {
name = json['name'];
localNames = json['local_names'] != null
? LocalNames.fromJson(json['local_names'])
: null;
localNames = json['local_names'] != null ? LocalNames.fromJson(json['local_names']) : null;
lat = json['lat'];
lon = json['lon'];
country = json['country'];
Expand Down
11 changes: 4 additions & 7 deletions lib/data/models/location_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ class LocationModel {
Country? country;
Country? administrativeArea;

LocationModel(
{this.key, this.localizedName, this.country, this.administrativeArea});
LocationModel({this.key, this.localizedName, this.country, this.administrativeArea});

LocationModel.fromJson(Map<String, dynamic> json) {
key = json['Key'];
localizedName = json['LocalizedName'];
country =
json['Country'] != null ? Country.fromJson(json['Country']) : null;
administrativeArea = json['AdministrativeArea'] != null
? Country.fromJson(json['AdministrativeArea'])
: null;
country = json['Country'] != null ? Country.fromJson(json['Country']) : null;
administrativeArea =
json['AdministrativeArea'] != null ? Country.fromJson(json['AdministrativeArea']) : null;
}

Map<String, dynamic> toJson() {
Expand Down
8 changes: 2 additions & 6 deletions lib/data/models/weather_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class WeatherModel {
weatherIcon = json['WeatherIcon'];
hasPrecipitation = json['HasPrecipitation'];
isDayTime = json['IsDayTime'];
temperature = json['Temperature'] != null
? Temperature.fromJson(json['Temperature'])
: null;
temperature = json['Temperature'] != null ? Temperature.fromJson(json['Temperature']) : null;
realFeelTemperature = json['RealFeelTemperature'] != null
? Temperature.fromJson(json['RealFeelTemperature'])
: null;
Expand Down Expand Up @@ -120,9 +118,7 @@ class Wind {
Wind({this.direction, this.speed});

Wind.fromJson(Map<String, dynamic> json) {
direction = json['Direction'] != null
? Direction.fromJson(json['Direction'])
: null;
direction = json['Direction'] != null ? Direction.fromJson(json['Direction']) : null;
speed = json['Speed'] != null ? Temperature.fromJson(json['Speed']) : null;
}

Expand Down
3 changes: 1 addition & 2 deletions lib/logic/locations/locations_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class LocationsCubit extends Cubit<LocationsState> {

Future<void> addLocation(LocationModel location) async {
savedLocations.add(location);
emit(state.copywith(
status: LocationsStatus.success, savedLocations: savedLocations));
emit(state.copywith(status: LocationsStatus.success, savedLocations: savedLocations));
}
}
3 changes: 1 addition & 2 deletions lib/logic/locations/locations_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class LocationsState extends Equatable {
}

LocationsState toMap() {
return LocationsState(
status: status, locations: locations, savedLocations: savedLocations);
return LocationsState(status: status, locations: locations, savedLocations: savedLocations);
}

@override
Expand Down
6 changes: 2 additions & 4 deletions lib/logic/user_permission/user_permission_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ class UserPermissionCubit extends Cubit<UserPermissionState> {
}

locationData = await Geolocator.getCurrentPosition();
await AccuWeatherAPI.getGeoPositionnKey(
locationData.latitude, locationData.longitude)
await AccuWeatherAPI.getGeoPositionnKey(locationData.latitude, locationData.longitude)
.then((positionKey) {
emit(state.copywith(
status: PermissionStatus.always, positionKey: positionKey));
emit(state.copywith(status: PermissionStatus.always, positionKey: positionKey));
return 0;
});
// log('${_locationData!.latitude!.toString()}, ${_locationData!.longitude!.toString()}}');
Expand Down
17 changes: 4 additions & 13 deletions lib/logic/user_permission/user_permission_state.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
part of 'user_permission_cubit.dart';

enum PermissionStatus {
always,
denied,
deniedForever,
whileInUse,
unableToDetermine
}
enum PermissionStatus { always, denied, deniedForever, whileInUse, unableToDetermine }

class UserPermissionState extends Equatable {
final PermissionStatus status;
Expand All @@ -17,14 +11,11 @@ class UserPermissionState extends Equatable {
this.positionKey,
});

UserPermissionState copywith({PermissionStatus? status, int? positionKey}) =>
UserPermissionState(
status: status ?? this.status,
positionKey: positionKey ?? this.positionKey);
UserPermissionState copywith({PermissionStatus? status, int? positionKey}) => UserPermissionState(
status: status ?? this.status, positionKey: positionKey ?? this.positionKey);

factory UserPermissionState.fromJson(Map<String, dynamic> json) {
return UserPermissionState(
status: json['status'], positionKey: json['positionKey']);
return UserPermissionState(status: json['status'], positionKey: json['positionKey']);
}

UserPermissionState toMap() {
Expand Down
7 changes: 2 additions & 5 deletions lib/logic/weather/weather_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ part 'weather_state.dart';
class WeatherCubit extends Cubit<WeatherState> {
final WeatherRepo weatherRepo;

WeatherCubit(this.weatherRepo)
: super(const WeatherState(status: WeatherStatus.initial));
WeatherCubit(this.weatherRepo) : super(const WeatherState(status: WeatherStatus.initial));

Future<void> fetchWeather(int? cityKey) async {
if (cityKey == null) {
Expand All @@ -24,9 +23,7 @@ class WeatherCubit extends Cubit<WeatherState> {
try {
final weather = await weatherRepo.getWeather(cityKey);
emit(state.copyWith(
status: WeatherStatus.success,
forecast: weather.forecast,
weather: weather.weather));
status: WeatherStatus.success, forecast: weather.forecast, weather: weather.weather));
} catch (_) {
emit(state.copyWith(status: WeatherStatus.failure));
}
Expand Down
12 changes: 3 additions & 9 deletions lib/logic/weather/weather_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@ class WeatherState extends Equatable {
final WeatherModel? weather;
final ForecastModel? forecast;

const WeatherState(
{this.status = WeatherStatus.initial, this.forecast, this.weather});
const WeatherState({this.status = WeatherStatus.initial, this.forecast, this.weather});

WeatherState copyWith(
{WeatherStatus? status,
WeatherModel? weather,
ForecastModel? forecast}) =>
WeatherState copyWith({WeatherStatus? status, WeatherModel? weather, ForecastModel? forecast}) =>
WeatherState(
status: status ?? this.status,
forecast: forecast ?? this.forecast,
weather: weather ?? this.weather);

factory WeatherState.fromJson(Map<String, dynamic> json) {
return WeatherState(
forecast: json['forecast'],
status: json['status'],
weather: json['weather']);
forecast: json['forecast'], status: json['status'], weather: json['weather']);
}

Map<String, dynamic> toJson() {
Expand Down
Loading

0 comments on commit d7d0b99

Please sign in to comment.