Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session/7 #20

Merged
merged 8 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions build.yaml
morikann marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
targets:
$default:
builders:
source_gen|combining_builder:
options:
ignore_for_file:
- type=lint
- implicit_dynamic_parameter
- implicit_dynamic_type
- implicit_dynamic_method
- strict_raw_type
json_serializable:
options:
checked: true
field_rename: snake
44 changes: 13 additions & 31 deletions lib/model/weather_data.dart
Original file line number Diff line number Diff line change
@@ -1,37 +1,19 @@
import 'package:flutter_training/model/weather_condition.dart';
import 'package:flutter_training/utils/extention/enum.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

class WeatherData {
const WeatherData({
required this.weatherCondition,
required this.maxTemperature,
required this.minTemperature,
required this.date,
});
part 'weather_data.freezed.dart';

factory WeatherData.fromJson(Map<String, dynamic> json) {
final weatherCondition = WeatherCondition.values
.byNameOrNull(json['weather_condition'].toString());
if (weatherCondition == null) {
throw const FormatException('Invalid value for [WeatherCondition].');
}
part 'weather_data.g.dart';

final maxTemperature = int.parse(json['max_temperature'].toString());
@freezed
class WeatherData with _$WeatherData {
const factory WeatherData({
required WeatherCondition weatherCondition,
required int maxTemperature,
required int minTemperature,
required DateTime date,
}) = _WeatherData;

final minTemperature = int.parse(json['min_temperature'].toString());

final date = DateTime.parse(json['date']?.toString() ?? '');

return WeatherData(
weatherCondition: weatherCondition,
maxTemperature: maxTemperature,
minTemperature: minTemperature,
date: date,
);
}

final WeatherCondition weatherCondition;
final int maxTemperature;
final int minTemperature;
final DateTime date;
factory WeatherData.fromJson(Map<String, dynamic> json) =>
_$WeatherDataFromJson(json);
}
219 changes: 219 additions & 0 deletions lib/model/weather_data.freezed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark

part of 'weather_data.dart';

// **************************************************************************
// FreezedGenerator
// **************************************************************************

T _$identity<T>(T value) => value;

final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');

WeatherData _$WeatherDataFromJson(Map<String, dynamic> json) {
return _WeatherData.fromJson(json);
}

/// @nodoc
mixin _$WeatherData {
WeatherCondition get weatherCondition => throw _privateConstructorUsedError;
int get maxTemperature => throw _privateConstructorUsedError;
int get minTemperature => throw _privateConstructorUsedError;
DateTime get date => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$WeatherDataCopyWith<WeatherData> get copyWith =>
throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $WeatherDataCopyWith<$Res> {
factory $WeatherDataCopyWith(
WeatherData value, $Res Function(WeatherData) then) =
_$WeatherDataCopyWithImpl<$Res, WeatherData>;
@useResult
$Res call(
{WeatherCondition weatherCondition,
int maxTemperature,
int minTemperature,
DateTime date});
}

/// @nodoc
class _$WeatherDataCopyWithImpl<$Res, $Val extends WeatherData>
implements $WeatherDataCopyWith<$Res> {
_$WeatherDataCopyWithImpl(this._value, this._then);

// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;

@pragma('vm:prefer-inline')
@override
$Res call({
Object? weatherCondition = null,
Object? maxTemperature = null,
Object? minTemperature = null,
Object? date = null,
}) {
return _then(_value.copyWith(
weatherCondition: null == weatherCondition
? _value.weatherCondition
: weatherCondition // ignore: cast_nullable_to_non_nullable
as WeatherCondition,
maxTemperature: null == maxTemperature
? _value.maxTemperature
: maxTemperature // ignore: cast_nullable_to_non_nullable
as int,
minTemperature: null == minTemperature
? _value.minTemperature
: minTemperature // ignore: cast_nullable_to_non_nullable
as int,
date: null == date
? _value.date
: date // ignore: cast_nullable_to_non_nullable
as DateTime,
) as $Val);
}
}

/// @nodoc
abstract class _$$_WeatherDataCopyWith<$Res>
implements $WeatherDataCopyWith<$Res> {
factory _$$_WeatherDataCopyWith(
_$_WeatherData value, $Res Function(_$_WeatherData) then) =
__$$_WeatherDataCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{WeatherCondition weatherCondition,
int maxTemperature,
int minTemperature,
DateTime date});
}

/// @nodoc
class __$$_WeatherDataCopyWithImpl<$Res>
extends _$WeatherDataCopyWithImpl<$Res, _$_WeatherData>
implements _$$_WeatherDataCopyWith<$Res> {
__$$_WeatherDataCopyWithImpl(
_$_WeatherData _value, $Res Function(_$_WeatherData) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? weatherCondition = null,
Object? maxTemperature = null,
Object? minTemperature = null,
Object? date = null,
}) {
return _then(_$_WeatherData(
weatherCondition: null == weatherCondition
? _value.weatherCondition
: weatherCondition // ignore: cast_nullable_to_non_nullable
as WeatherCondition,
maxTemperature: null == maxTemperature
? _value.maxTemperature
: maxTemperature // ignore: cast_nullable_to_non_nullable
as int,
minTemperature: null == minTemperature
? _value.minTemperature
: minTemperature // ignore: cast_nullable_to_non_nullable
as int,
date: null == date
? _value.date
: date // ignore: cast_nullable_to_non_nullable
as DateTime,
));
}
}

/// @nodoc
@JsonSerializable()
class _$_WeatherData implements _WeatherData {
const _$_WeatherData(
{required this.weatherCondition,
required this.maxTemperature,
required this.minTemperature,
required this.date});

factory _$_WeatherData.fromJson(Map<String, dynamic> json) =>
_$$_WeatherDataFromJson(json);

@override
final WeatherCondition weatherCondition;
@override
final int maxTemperature;
@override
final int minTemperature;
@override
final DateTime date;

@override
String toString() {
return 'WeatherData(weatherCondition: $weatherCondition, maxTemperature: $maxTemperature, minTemperature: $minTemperature, date: $date)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_WeatherData &&
(identical(other.weatherCondition, weatherCondition) ||
other.weatherCondition == weatherCondition) &&
(identical(other.maxTemperature, maxTemperature) ||
other.maxTemperature == maxTemperature) &&
(identical(other.minTemperature, minTemperature) ||
other.minTemperature == minTemperature) &&
(identical(other.date, date) || other.date == date));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(
runtimeType, weatherCondition, maxTemperature, minTemperature, date);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_WeatherDataCopyWith<_$_WeatherData> get copyWith =>
__$$_WeatherDataCopyWithImpl<_$_WeatherData>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$_WeatherDataToJson(
this,
);
}
}

abstract class _WeatherData implements WeatherData {
const factory _WeatherData(
{required final WeatherCondition weatherCondition,
required final int maxTemperature,
required final int minTemperature,
required final DateTime date}) = _$_WeatherData;

factory _WeatherData.fromJson(Map<String, dynamic> json) =
_$_WeatherData.fromJson;

@override
WeatherCondition get weatherCondition;
@override
int get maxTemperature;
@override
int get minTemperature;
@override
DateTime get date;
@override
@JsonKey(ignore: true)
_$$_WeatherDataCopyWith<_$_WeatherData> get copyWith =>
throw _privateConstructorUsedError;
}
45 changes: 45 additions & 0 deletions lib/model/weather_data.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 15 additions & 12 deletions lib/model/weather_request.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
class WeatherRequest {
WeatherRequest({required this.area, required this.date});

final String area;
final DateTime date;

Map<String, dynamic> toJson() {
return {
'area': area,
'date': date.toString(),
};
}
import 'package:freezed_annotation/freezed_annotation.dart';

part 'weather_request.freezed.dart';

part 'weather_request.g.dart';

@freezed
class WeatherRequest with _$WeatherRequest {
const factory WeatherRequest({
required String area,
required DateTime date,
}) = _WeatherRequest;

factory WeatherRequest.fromJson(Map<String, dynamic> json) =>
_$WeatherRequestFromJson(json);
}
Loading
Loading