Rebuild models

This commit is contained in:
Ankit Mahato
2025-06-29 06:00:21 +05:30
parent f4e09a54e3
commit 39cd3a7e26
7 changed files with 371 additions and 345 deletions

View File

@@ -13,10 +13,7 @@ part 'http_request_model.g.dart';
class HttpRequestModel with _$HttpRequestModel {
const HttpRequestModel._();
@JsonSerializable(
explicitToJson: true,
anyMap: true,
)
@JsonSerializable(explicitToJson: true, anyMap: true)
const factory HttpRequestModel({
@Default(HTTPVerb.get) HTTPVerb method,
@Default("") String url,

View File

@@ -12,7 +12,8 @@ part of 'http_request_model.dart';
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#adding-getters-and-methods-to-our-models');
'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#adding-getters-and-methods-to-our-models',
);
HttpRequestModel _$HttpRequestModelFromJson(Map<String, dynamic> json) {
return _HttpRequestModel.fromJson(json);
@@ -44,11 +45,12 @@ mixin _$HttpRequestModel {
/// @nodoc
abstract class $HttpRequestModelCopyWith<$Res> {
factory $HttpRequestModelCopyWith(
HttpRequestModel value, $Res Function(HttpRequestModel) then) =
_$HttpRequestModelCopyWithImpl<$Res, HttpRequestModel>;
HttpRequestModel value,
$Res Function(HttpRequestModel) then,
) = _$HttpRequestModelCopyWithImpl<$Res, HttpRequestModel>;
@useResult
$Res call(
{HTTPVerb method,
$Res call({
HTTPVerb method,
String url,
List<NameValueModel>? headers,
List<NameValueModel>? params,
@@ -57,7 +59,8 @@ abstract class $HttpRequestModelCopyWith<$Res> {
ContentType bodyContentType,
String? body,
String? query,
List<FormDataModel>? formData});
List<FormDataModel>? formData,
});
}
/// @nodoc
@@ -86,7 +89,8 @@ class _$HttpRequestModelCopyWithImpl<$Res, $Val extends HttpRequestModel>
Object? query = freezed,
Object? formData = freezed,
}) {
return _then(_value.copyWith(
return _then(
_value.copyWith(
method: null == method
? _value.method
: method // ignore: cast_nullable_to_non_nullable
@@ -127,20 +131,23 @@ class _$HttpRequestModelCopyWithImpl<$Res, $Val extends HttpRequestModel>
? _value.formData
: formData // ignore: cast_nullable_to_non_nullable
as List<FormDataModel>?,
) as $Val);
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$HttpRequestModelImplCopyWith<$Res>
implements $HttpRequestModelCopyWith<$Res> {
factory _$$HttpRequestModelImplCopyWith(_$HttpRequestModelImpl value,
$Res Function(_$HttpRequestModelImpl) then) =
__$$HttpRequestModelImplCopyWithImpl<$Res>;
factory _$$HttpRequestModelImplCopyWith(
_$HttpRequestModelImpl value,
$Res Function(_$HttpRequestModelImpl) then,
) = __$$HttpRequestModelImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{HTTPVerb method,
$Res call({
HTTPVerb method,
String url,
List<NameValueModel>? headers,
List<NameValueModel>? params,
@@ -149,16 +156,18 @@ abstract class _$$HttpRequestModelImplCopyWith<$Res>
ContentType bodyContentType,
String? body,
String? query,
List<FormDataModel>? formData});
List<FormDataModel>? formData,
});
}
/// @nodoc
class __$$HttpRequestModelImplCopyWithImpl<$Res>
extends _$HttpRequestModelCopyWithImpl<$Res, _$HttpRequestModelImpl>
implements _$$HttpRequestModelImplCopyWith<$Res> {
__$$HttpRequestModelImplCopyWithImpl(_$HttpRequestModelImpl _value,
$Res Function(_$HttpRequestModelImpl) _then)
: super(_value, _then);
__$$HttpRequestModelImplCopyWithImpl(
_$HttpRequestModelImpl _value,
$Res Function(_$HttpRequestModelImpl) _then,
) : super(_value, _then);
/// Create a copy of HttpRequestModel
/// with the given fields replaced by the non-null parameter values.
@@ -176,7 +185,8 @@ class __$$HttpRequestModelImplCopyWithImpl<$Res>
Object? query = freezed,
Object? formData = freezed,
}) {
return _then(_$HttpRequestModelImpl(
return _then(
_$HttpRequestModelImpl(
method: null == method
? _value.method
: method // ignore: cast_nullable_to_non_nullable
@@ -217,7 +227,8 @@ class __$$HttpRequestModelImplCopyWithImpl<$Res>
? _value._formData
: formData // ignore: cast_nullable_to_non_nullable
as List<FormDataModel>?,
));
),
);
}
}
@@ -225,8 +236,8 @@ class __$$HttpRequestModelImplCopyWithImpl<$Res>
@JsonSerializable(explicitToJson: true, anyMap: true)
class _$HttpRequestModelImpl extends _HttpRequestModel {
const _$HttpRequestModelImpl(
{this.method = HTTPVerb.get,
const _$HttpRequestModelImpl({
this.method = HTTPVerb.get,
this.url = "",
final List<NameValueModel>? headers,
final List<NameValueModel>? params,
@@ -235,8 +246,8 @@ class _$HttpRequestModelImpl extends _HttpRequestModel {
this.bodyContentType = ContentType.json,
this.body,
this.query,
final List<FormDataModel>? formData})
: _headers = headers,
final List<FormDataModel>? formData,
}) : _headers = headers,
_params = params,
_isHeaderEnabledList = isHeaderEnabledList,
_isParamEnabledList = isParamEnabledList,
@@ -325,10 +336,14 @@ class _$HttpRequestModelImpl extends _HttpRequestModel {
(identical(other.url, url) || other.url == url) &&
const DeepCollectionEquality().equals(other._headers, _headers) &&
const DeepCollectionEquality().equals(other._params, _params) &&
const DeepCollectionEquality()
.equals(other._isHeaderEnabledList, _isHeaderEnabledList) &&
const DeepCollectionEquality()
.equals(other._isParamEnabledList, _isParamEnabledList) &&
const DeepCollectionEquality().equals(
other._isHeaderEnabledList,
_isHeaderEnabledList,
) &&
const DeepCollectionEquality().equals(
other._isParamEnabledList,
_isParamEnabledList,
) &&
(identical(other.bodyContentType, bodyContentType) ||
other.bodyContentType == bodyContentType) &&
(identical(other.body, body) || other.body == body) &&
@@ -349,7 +364,8 @@ class _$HttpRequestModelImpl extends _HttpRequestModel {
bodyContentType,
body,
query,
const DeepCollectionEquality().hash(_formData));
const DeepCollectionEquality().hash(_formData),
);
/// Create a copy of HttpRequestModel
/// with the given fields replaced by the non-null parameter values.
@@ -358,19 +374,19 @@ class _$HttpRequestModelImpl extends _HttpRequestModel {
@pragma('vm:prefer-inline')
_$$HttpRequestModelImplCopyWith<_$HttpRequestModelImpl> get copyWith =>
__$$HttpRequestModelImplCopyWithImpl<_$HttpRequestModelImpl>(
this, _$identity);
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$HttpRequestModelImplToJson(
this,
);
return _$$HttpRequestModelImplToJson(this);
}
}
abstract class _HttpRequestModel extends HttpRequestModel {
const factory _HttpRequestModel(
{final HTTPVerb method,
const factory _HttpRequestModel({
final HTTPVerb method,
final String url,
final List<NameValueModel>? headers,
final List<NameValueModel>? params,
@@ -379,7 +395,8 @@ abstract class _HttpRequestModel extends HttpRequestModel {
final ContentType bodyContentType,
final String? body,
final String? query,
final List<FormDataModel>? formData}) = _$HttpRequestModelImpl;
final List<FormDataModel>? formData,
}) = _$HttpRequestModelImpl;
const _HttpRequestModel._() : super._();
factory _HttpRequestModel.fromJson(Map<String, dynamic> json) =

View File

@@ -6,18 +6,17 @@ part of 'http_request_model.dart';
// JsonSerializableGenerator
// **************************************************************************
_$HttpRequestModelImpl _$$HttpRequestModelImplFromJson(Map json) =>
_$HttpRequestModelImpl(
method: $enumDecodeNullable(_$HTTPVerbEnumMap, json['method']) ??
HTTPVerb.get,
_$HttpRequestModelImpl _$$HttpRequestModelImplFromJson(
Map json,
) => _$HttpRequestModelImpl(
method:
$enumDecodeNullable(_$HTTPVerbEnumMap, json['method']) ?? HTTPVerb.get,
url: json['url'] as String? ?? "",
headers: (json['headers'] as List<dynamic>?)
?.map((e) =>
NameValueModel.fromJson(Map<String, Object?>.from(e as Map)))
?.map((e) => NameValueModel.fromJson(Map<String, Object?>.from(e as Map)))
.toList(),
params: (json['params'] as List<dynamic>?)
?.map((e) =>
NameValueModel.fromJson(Map<String, Object?>.from(e as Map)))
?.map((e) => NameValueModel.fromJson(Map<String, Object?>.from(e as Map)))
.toList(),
isHeaderEnabledList: (json['isHeaderEnabledList'] as List<dynamic>?)
?.map((e) => e as bool)
@@ -31,14 +30,13 @@ _$HttpRequestModelImpl _$$HttpRequestModelImplFromJson(Map json) =>
body: json['body'] as String?,
query: json['query'] as String?,
formData: (json['formData'] as List<dynamic>?)
?.map((e) =>
FormDataModel.fromJson(Map<String, Object?>.from(e as Map)))
?.map((e) => FormDataModel.fromJson(Map<String, Object?>.from(e as Map)))
.toList(),
);
);
Map<String, dynamic> _$$HttpRequestModelImplToJson(
_$HttpRequestModelImpl instance) =>
<String, dynamic>{
_$HttpRequestModelImpl instance,
) => <String, dynamic>{
'method': _$HTTPVerbEnumMap[instance.method]!,
'url': instance.url,
'headers': instance.headers?.map((e) => e.toJson()).toList(),
@@ -49,7 +47,7 @@ Map<String, dynamic> _$$HttpRequestModelImplToJson(
'body': instance.body,
'query': instance.query,
'formData': instance.formData?.map((e) => e.toJson()).toList(),
};
};
const _$HTTPVerbEnumMap = {
HTTPVerb.get: 'get',

View File

@@ -44,10 +44,7 @@ class DurationConverter implements JsonConverter<Duration?, int?> {
class HttpResponseModel with _$HttpResponseModel {
const HttpResponseModel._();
@JsonSerializable(
explicitToJson: true,
anyMap: true,
)
@JsonSerializable(explicitToJson: true, anyMap: true)
const factory HttpResponseModel({
int? statusCode,
Map<String, String>? headers,
@@ -65,9 +62,9 @@ class HttpResponseModel with _$HttpResponseModel {
MediaType? get mediaType => getMediaTypeFromHeaders(headers);
HttpResponseModel fromResponse({required Response response, Duration? time}) {
final responseHeaders = mergeMaps(
{HttpHeaders.contentLengthHeader: response.contentLength.toString()},
response.headers);
final responseHeaders = mergeMaps({
HttpHeaders.contentLengthHeader: response.contentLength.toString(),
}, response.headers);
MediaType? mediaType = getMediaTypeFromHeaders(responseHeaders);
final body = (mediaType?.subtype == kSubTypeJson)
? utf8.decode(response.bodyBytes)

View File

@@ -12,7 +12,8 @@ part of 'http_response_model.dart';
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#adding-getters-and-methods-to-our-models');
'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#adding-getters-and-methods-to-our-models',
);
HttpResponseModel _$HttpResponseModelFromJson(Map<String, dynamic> json) {
return _HttpResponseModel.fromJson(json);
@@ -43,17 +44,19 @@ mixin _$HttpResponseModel {
/// @nodoc
abstract class $HttpResponseModelCopyWith<$Res> {
factory $HttpResponseModelCopyWith(
HttpResponseModel value, $Res Function(HttpResponseModel) then) =
_$HttpResponseModelCopyWithImpl<$Res, HttpResponseModel>;
HttpResponseModel value,
$Res Function(HttpResponseModel) then,
) = _$HttpResponseModelCopyWithImpl<$Res, HttpResponseModel>;
@useResult
$Res call(
{int? statusCode,
$Res call({
int? statusCode,
Map<String, String>? headers,
Map<String, String>? requestHeaders,
String? body,
String? formattedBody,
@Uint8ListConverter() Uint8List? bodyBytes,
@DurationConverter() Duration? time});
@DurationConverter() Duration? time,
});
}
/// @nodoc
@@ -79,7 +82,8 @@ class _$HttpResponseModelCopyWithImpl<$Res, $Val extends HttpResponseModel>
Object? bodyBytes = freezed,
Object? time = freezed,
}) {
return _then(_value.copyWith(
return _then(
_value.copyWith(
statusCode: freezed == statusCode
? _value.statusCode
: statusCode // ignore: cast_nullable_to_non_nullable
@@ -108,35 +112,40 @@ class _$HttpResponseModelCopyWithImpl<$Res, $Val extends HttpResponseModel>
? _value.time
: time // ignore: cast_nullable_to_non_nullable
as Duration?,
) as $Val);
)
as $Val,
);
}
}
/// @nodoc
abstract class _$$HttpResponseModelImplCopyWith<$Res>
implements $HttpResponseModelCopyWith<$Res> {
factory _$$HttpResponseModelImplCopyWith(_$HttpResponseModelImpl value,
$Res Function(_$HttpResponseModelImpl) then) =
__$$HttpResponseModelImplCopyWithImpl<$Res>;
factory _$$HttpResponseModelImplCopyWith(
_$HttpResponseModelImpl value,
$Res Function(_$HttpResponseModelImpl) then,
) = __$$HttpResponseModelImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{int? statusCode,
$Res call({
int? statusCode,
Map<String, String>? headers,
Map<String, String>? requestHeaders,
String? body,
String? formattedBody,
@Uint8ListConverter() Uint8List? bodyBytes,
@DurationConverter() Duration? time});
@DurationConverter() Duration? time,
});
}
/// @nodoc
class __$$HttpResponseModelImplCopyWithImpl<$Res>
extends _$HttpResponseModelCopyWithImpl<$Res, _$HttpResponseModelImpl>
implements _$$HttpResponseModelImplCopyWith<$Res> {
__$$HttpResponseModelImplCopyWithImpl(_$HttpResponseModelImpl _value,
$Res Function(_$HttpResponseModelImpl) _then)
: super(_value, _then);
__$$HttpResponseModelImplCopyWithImpl(
_$HttpResponseModelImpl _value,
$Res Function(_$HttpResponseModelImpl) _then,
) : super(_value, _then);
/// Create a copy of HttpResponseModel
/// with the given fields replaced by the non-null parameter values.
@@ -151,7 +160,8 @@ class __$$HttpResponseModelImplCopyWithImpl<$Res>
Object? bodyBytes = freezed,
Object? time = freezed,
}) {
return _then(_$HttpResponseModelImpl(
return _then(
_$HttpResponseModelImpl(
statusCode: freezed == statusCode
? _value.statusCode
: statusCode // ignore: cast_nullable_to_non_nullable
@@ -180,7 +190,8 @@ class __$$HttpResponseModelImplCopyWithImpl<$Res>
? _value.time
: time // ignore: cast_nullable_to_non_nullable
as Duration?,
));
),
);
}
}
@@ -188,15 +199,15 @@ class __$$HttpResponseModelImplCopyWithImpl<$Res>
@JsonSerializable(explicitToJson: true, anyMap: true)
class _$HttpResponseModelImpl extends _HttpResponseModel {
const _$HttpResponseModelImpl(
{this.statusCode,
const _$HttpResponseModelImpl({
this.statusCode,
final Map<String, String>? headers,
final Map<String, String>? requestHeaders,
this.body,
this.formattedBody,
@Uint8ListConverter() this.bodyBytes,
@DurationConverter() this.time})
: _headers = headers,
@DurationConverter() this.time,
}) : _headers = headers,
_requestHeaders = requestHeaders,
super._();
@@ -249,8 +260,10 @@ class _$HttpResponseModelImpl extends _HttpResponseModel {
(identical(other.statusCode, statusCode) ||
other.statusCode == statusCode) &&
const DeepCollectionEquality().equals(other._headers, _headers) &&
const DeepCollectionEquality()
.equals(other._requestHeaders, _requestHeaders) &&
const DeepCollectionEquality().equals(
other._requestHeaders,
_requestHeaders,
) &&
(identical(other.body, body) || other.body == body) &&
(identical(other.formattedBody, formattedBody) ||
other.formattedBody == formattedBody) &&
@@ -268,7 +281,8 @@ class _$HttpResponseModelImpl extends _HttpResponseModel {
body,
formattedBody,
const DeepCollectionEquality().hash(bodyBytes),
time);
time,
);
/// Create a copy of HttpResponseModel
/// with the given fields replaced by the non-null parameter values.
@@ -277,25 +291,26 @@ class _$HttpResponseModelImpl extends _HttpResponseModel {
@pragma('vm:prefer-inline')
_$$HttpResponseModelImplCopyWith<_$HttpResponseModelImpl> get copyWith =>
__$$HttpResponseModelImplCopyWithImpl<_$HttpResponseModelImpl>(
this, _$identity);
this,
_$identity,
);
@override
Map<String, dynamic> toJson() {
return _$$HttpResponseModelImplToJson(
this,
);
return _$$HttpResponseModelImplToJson(this);
}
}
abstract class _HttpResponseModel extends HttpResponseModel {
const factory _HttpResponseModel(
{final int? statusCode,
const factory _HttpResponseModel({
final int? statusCode,
final Map<String, String>? headers,
final Map<String, String>? requestHeaders,
final String? body,
final String? formattedBody,
@Uint8ListConverter() final Uint8List? bodyBytes,
@DurationConverter() final Duration? time}) = _$HttpResponseModelImpl;
@DurationConverter() final Duration? time,
}) = _$HttpResponseModelImpl;
const _HttpResponseModel._() : super._();
factory _HttpResponseModel.fromJson(Map<String, dynamic> json) =

View File

@@ -17,14 +17,15 @@ _$HttpResponseModelImpl _$$HttpResponseModelImplFromJson(Map json) =>
),
body: json['body'] as String?,
formattedBody: json['formattedBody'] as String?,
bodyBytes:
const Uint8ListConverter().fromJson(json['bodyBytes'] as List<int>?),
bodyBytes: const Uint8ListConverter().fromJson(
json['bodyBytes'] as List<int>?,
),
time: const DurationConverter().fromJson((json['time'] as num?)?.toInt()),
);
Map<String, dynamic> _$$HttpResponseModelImplToJson(
_$HttpResponseModelImpl instance) =>
<String, dynamic>{
_$HttpResponseModelImpl instance,
) => <String, dynamic>{
'statusCode': instance.statusCode,
'headers': instance.headers,
'requestHeaders': instance.requestHeaders,
@@ -32,4 +33,4 @@ Map<String, dynamic> _$$HttpResponseModelImplToJson(
'formattedBody': instance.formattedBody,
'bodyBytes': const Uint8ListConverter().toJson(instance.bodyBytes),
'time': const DurationConverter().toJson(instance.time),
};
};

View File

@@ -15,6 +15,7 @@ dependencies:
http: ^1.3.0
http_parser: ^4.1.2
json5: ^0.8.2
json_annotation: ^4.9.0
seed: ^0.0.3
xml: ^6.3.0