From 4bafdfe1b9e99fe01eb0c96e74eb6ba6e6b5760b Mon Sep 17 00:00:00 2001 From: Erkin Ovlyagulyyev Date: Thu, 29 Jan 2026 13:06:11 +0500 Subject: [PATCH] refactor: remove Freezed and JsonSerializable dependencies, replace with manual implementations for VideoSize and VideoResponse models --- lib/src/models/video_response.dart | 96 +++-- lib/src/models/video_response.freezed.dart | 434 --------------------- lib/src/models/video_response.g.dart | 37 -- pubspec.yaml | 16 +- 4 files changed, 77 insertions(+), 506 deletions(-) delete mode 100644 lib/src/models/video_response.freezed.dart delete mode 100644 lib/src/models/video_response.g.dart diff --git a/lib/src/models/video_response.dart b/lib/src/models/video_response.dart index 739ab65..0b2d96b 100644 --- a/lib/src/models/video_response.dart +++ b/lib/src/models/video_response.dart @@ -1,33 +1,83 @@ -import 'package:freezed_annotation/freezed_annotation.dart'; +class VideoSize { + const VideoSize({required this.width, required this.height}); -part 'video_response.freezed.dart'; -part 'video_response.g.dart'; + final int width; + final int height; -@freezed -class VideoSize with _$VideoSize { - const factory VideoSize({ - required int width, - required int height, - }) = _VideoSize; + factory VideoSize.fromJson(Map json) { + return VideoSize( + width: json['width'] as int, + height: json['height'] as int, + ); + } - factory VideoSize.fromJson(Map json) => - _$VideoSizeFromJson(json); + Map toJson() => {'width': width, 'height': height}; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is VideoSize && + runtimeType == other.runtimeType && + width == other.width && + height == other.height; + + @override + int get hashCode => Object.hash(width, height); + + @override + String toString() => 'VideoSize(width: $width, height: $height)'; } -@freezed -class VideoResponse with _$VideoResponse { - const factory VideoResponse({ - required String html, - required VideoSize size, - String? thumbnailUrl, - @Default(false) bool isVertical, - String? error, - }) = _VideoResponse; +class VideoResponse { + const VideoResponse({ + required this.html, + required this.size, + this.thumbnailUrl, + this.isVertical = false, + this.error, + }); + + final String html; + final VideoSize size; + final String? thumbnailUrl; + final bool isVertical; + final String? error; - factory VideoResponse.fromJson(Map json) => - _$VideoResponseFromJson(json); + factory VideoResponse.fromJson(Map json) { + return VideoResponse( + html: json['html'] as String, + size: VideoSize.fromJson(json['size'] as Map), + thumbnailUrl: json['thumbnailUrl'] as String?, + isVertical: json['isVertical'] as bool? ?? false, + error: json['error'] as String?, + ); + } - const VideoResponse._(); + Map toJson() => { + 'html': html, + 'size': size.toJson(), + if (thumbnailUrl != null) 'thumbnailUrl': thumbnailUrl, + 'isVertical': isVertical, + if (error != null) 'error': error, + }; double get aspectRatio => size.width / size.height; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is VideoResponse && + runtimeType == other.runtimeType && + html == other.html && + size == other.size && + thumbnailUrl == other.thumbnailUrl && + isVertical == other.isVertical && + error == other.error; + + @override + int get hashCode => Object.hash(html, size, thumbnailUrl, isVertical, error); + + @override + String toString() => + 'VideoResponse(html: $html, size: $size, thumbnailUrl: $thumbnailUrl, isVertical: $isVertical, error: $error)'; } diff --git a/lib/src/models/video_response.freezed.dart b/lib/src/models/video_response.freezed.dart deleted file mode 100644 index aa74f84..0000000 --- a/lib/src/models/video_response.freezed.dart +++ /dev/null @@ -1,434 +0,0 @@ -// 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 'video_response.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(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'); - -VideoSize _$VideoSizeFromJson(Map json) { - return _VideoSize.fromJson(json); -} - -/// @nodoc -mixin _$VideoSize { - int get width => throw _privateConstructorUsedError; - int get height => throw _privateConstructorUsedError; - - /// Serializes this VideoSize to a JSON map. - Map toJson() => throw _privateConstructorUsedError; - - /// Create a copy of VideoSize - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - $VideoSizeCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $VideoSizeCopyWith<$Res> { - factory $VideoSizeCopyWith(VideoSize value, $Res Function(VideoSize) then) = - _$VideoSizeCopyWithImpl<$Res, VideoSize>; - @useResult - $Res call({int width, int height}); -} - -/// @nodoc -class _$VideoSizeCopyWithImpl<$Res, $Val extends VideoSize> - implements $VideoSizeCopyWith<$Res> { - _$VideoSizeCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of VideoSize - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? width = null, - Object? height = null, - }) { - return _then(_value.copyWith( - width: null == width - ? _value.width - : width // ignore: cast_nullable_to_non_nullable - as int, - height: null == height - ? _value.height - : height // ignore: cast_nullable_to_non_nullable - as int, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$VideoSizeImplCopyWith<$Res> - implements $VideoSizeCopyWith<$Res> { - factory _$$VideoSizeImplCopyWith( - _$VideoSizeImpl value, $Res Function(_$VideoSizeImpl) then) = - __$$VideoSizeImplCopyWithImpl<$Res>; - @override - @useResult - $Res call({int width, int height}); -} - -/// @nodoc -class __$$VideoSizeImplCopyWithImpl<$Res> - extends _$VideoSizeCopyWithImpl<$Res, _$VideoSizeImpl> - implements _$$VideoSizeImplCopyWith<$Res> { - __$$VideoSizeImplCopyWithImpl( - _$VideoSizeImpl _value, $Res Function(_$VideoSizeImpl) _then) - : super(_value, _then); - - /// Create a copy of VideoSize - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? width = null, - Object? height = null, - }) { - return _then(_$VideoSizeImpl( - width: null == width - ? _value.width - : width // ignore: cast_nullable_to_non_nullable - as int, - height: null == height - ? _value.height - : height // ignore: cast_nullable_to_non_nullable - as int, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$VideoSizeImpl implements _VideoSize { - const _$VideoSizeImpl({required this.width, required this.height}); - - factory _$VideoSizeImpl.fromJson(Map json) => - _$$VideoSizeImplFromJson(json); - - @override - final int width; - @override - final int height; - - @override - String toString() { - return 'VideoSize(width: $width, height: $height)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$VideoSizeImpl && - (identical(other.width, width) || other.width == width) && - (identical(other.height, height) || other.height == height)); - } - - @JsonKey(includeFromJson: false, includeToJson: false) - @override - int get hashCode => Object.hash(runtimeType, width, height); - - /// Create a copy of VideoSize - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$VideoSizeImplCopyWith<_$VideoSizeImpl> get copyWith => - __$$VideoSizeImplCopyWithImpl<_$VideoSizeImpl>(this, _$identity); - - @override - Map toJson() { - return _$$VideoSizeImplToJson( - this, - ); - } -} - -abstract class _VideoSize implements VideoSize { - const factory _VideoSize( - {required final int width, required final int height}) = _$VideoSizeImpl; - - factory _VideoSize.fromJson(Map json) = - _$VideoSizeImpl.fromJson; - - @override - int get width; - @override - int get height; - - /// Create a copy of VideoSize - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$VideoSizeImplCopyWith<_$VideoSizeImpl> get copyWith => - throw _privateConstructorUsedError; -} - -VideoResponse _$VideoResponseFromJson(Map json) { - return _VideoResponse.fromJson(json); -} - -/// @nodoc -mixin _$VideoResponse { - String get html => throw _privateConstructorUsedError; - VideoSize get size => throw _privateConstructorUsedError; - String? get thumbnailUrl => throw _privateConstructorUsedError; - bool get isVertical => throw _privateConstructorUsedError; - String? get error => throw _privateConstructorUsedError; - - /// Serializes this VideoResponse to a JSON map. - Map toJson() => throw _privateConstructorUsedError; - - /// Create a copy of VideoResponse - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - $VideoResponseCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $VideoResponseCopyWith<$Res> { - factory $VideoResponseCopyWith( - VideoResponse value, $Res Function(VideoResponse) then) = - _$VideoResponseCopyWithImpl<$Res, VideoResponse>; - @useResult - $Res call( - {String html, - VideoSize size, - String? thumbnailUrl, - bool isVertical, - String? error}); - - $VideoSizeCopyWith<$Res> get size; -} - -/// @nodoc -class _$VideoResponseCopyWithImpl<$Res, $Val extends VideoResponse> - implements $VideoResponseCopyWith<$Res> { - _$VideoResponseCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of VideoResponse - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? html = null, - Object? size = null, - Object? thumbnailUrl = freezed, - Object? isVertical = null, - Object? error = freezed, - }) { - return _then(_value.copyWith( - html: null == html - ? _value.html - : html // ignore: cast_nullable_to_non_nullable - as String, - size: null == size - ? _value.size - : size // ignore: cast_nullable_to_non_nullable - as VideoSize, - thumbnailUrl: freezed == thumbnailUrl - ? _value.thumbnailUrl - : thumbnailUrl // ignore: cast_nullable_to_non_nullable - as String?, - isVertical: null == isVertical - ? _value.isVertical - : isVertical // ignore: cast_nullable_to_non_nullable - as bool, - error: freezed == error - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as String?, - ) as $Val); - } - - /// Create a copy of VideoResponse - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $VideoSizeCopyWith<$Res> get size { - return $VideoSizeCopyWith<$Res>(_value.size, (value) { - return _then(_value.copyWith(size: value) as $Val); - }); - } -} - -/// @nodoc -abstract class _$$VideoResponseImplCopyWith<$Res> - implements $VideoResponseCopyWith<$Res> { - factory _$$VideoResponseImplCopyWith( - _$VideoResponseImpl value, $Res Function(_$VideoResponseImpl) then) = - __$$VideoResponseImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {String html, - VideoSize size, - String? thumbnailUrl, - bool isVertical, - String? error}); - - @override - $VideoSizeCopyWith<$Res> get size; -} - -/// @nodoc -class __$$VideoResponseImplCopyWithImpl<$Res> - extends _$VideoResponseCopyWithImpl<$Res, _$VideoResponseImpl> - implements _$$VideoResponseImplCopyWith<$Res> { - __$$VideoResponseImplCopyWithImpl( - _$VideoResponseImpl _value, $Res Function(_$VideoResponseImpl) _then) - : super(_value, _then); - - /// Create a copy of VideoResponse - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? html = null, - Object? size = null, - Object? thumbnailUrl = freezed, - Object? isVertical = null, - Object? error = freezed, - }) { - return _then(_$VideoResponseImpl( - html: null == html - ? _value.html - : html // ignore: cast_nullable_to_non_nullable - as String, - size: null == size - ? _value.size - : size // ignore: cast_nullable_to_non_nullable - as VideoSize, - thumbnailUrl: freezed == thumbnailUrl - ? _value.thumbnailUrl - : thumbnailUrl // ignore: cast_nullable_to_non_nullable - as String?, - isVertical: null == isVertical - ? _value.isVertical - : isVertical // ignore: cast_nullable_to_non_nullable - as bool, - error: freezed == error - ? _value.error - : error // ignore: cast_nullable_to_non_nullable - as String?, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$VideoResponseImpl extends _VideoResponse { - const _$VideoResponseImpl( - {required this.html, - required this.size, - this.thumbnailUrl, - this.isVertical = false, - this.error}) - : super._(); - - factory _$VideoResponseImpl.fromJson(Map json) => - _$$VideoResponseImplFromJson(json); - - @override - final String html; - @override - final VideoSize size; - @override - final String? thumbnailUrl; - @override - @JsonKey() - final bool isVertical; - @override - final String? error; - - @override - String toString() { - return 'VideoResponse(html: $html, size: $size, thumbnailUrl: $thumbnailUrl, isVertical: $isVertical, error: $error)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$VideoResponseImpl && - (identical(other.html, html) || other.html == html) && - (identical(other.size, size) || other.size == size) && - (identical(other.thumbnailUrl, thumbnailUrl) || - other.thumbnailUrl == thumbnailUrl) && - (identical(other.isVertical, isVertical) || - other.isVertical == isVertical) && - (identical(other.error, error) || other.error == error)); - } - - @JsonKey(includeFromJson: false, includeToJson: false) - @override - int get hashCode => - Object.hash(runtimeType, html, size, thumbnailUrl, isVertical, error); - - /// Create a copy of VideoResponse - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$VideoResponseImplCopyWith<_$VideoResponseImpl> get copyWith => - __$$VideoResponseImplCopyWithImpl<_$VideoResponseImpl>(this, _$identity); - - @override - Map toJson() { - return _$$VideoResponseImplToJson( - this, - ); - } -} - -abstract class _VideoResponse extends VideoResponse { - const factory _VideoResponse( - {required final String html, - required final VideoSize size, - final String? thumbnailUrl, - final bool isVertical, - final String? error}) = _$VideoResponseImpl; - const _VideoResponse._() : super._(); - - factory _VideoResponse.fromJson(Map json) = - _$VideoResponseImpl.fromJson; - - @override - String get html; - @override - VideoSize get size; - @override - String? get thumbnailUrl; - @override - bool get isVertical; - @override - String? get error; - - /// Create a copy of VideoResponse - /// with the given fields replaced by the non-null parameter values. - @override - @JsonKey(includeFromJson: false, includeToJson: false) - _$$VideoResponseImplCopyWith<_$VideoResponseImpl> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/lib/src/models/video_response.g.dart b/lib/src/models/video_response.g.dart deleted file mode 100644 index 7005d1f..0000000 --- a/lib/src/models/video_response.g.dart +++ /dev/null @@ -1,37 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'video_response.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -_$VideoSizeImpl _$$VideoSizeImplFromJson(Map json) => - _$VideoSizeImpl( - width: (json['width'] as num).toInt(), - height: (json['height'] as num).toInt(), - ); - -Map _$$VideoSizeImplToJson(_$VideoSizeImpl instance) => - { - 'width': instance.width, - 'height': instance.height, - }; - -_$VideoResponseImpl _$$VideoResponseImplFromJson(Map json) => - _$VideoResponseImpl( - html: json['html'] as String, - size: VideoSize.fromJson(json['size'] as Map), - thumbnailUrl: json['thumbnailUrl'] as String?, - isVertical: json['isVertical'] as bool? ?? false, - error: json['error'] as String?, - ); - -Map _$$VideoResponseImplToJson(_$VideoResponseImpl instance) => - { - 'html': instance.html, - 'size': instance.size, - 'thumbnailUrl': instance.thumbnailUrl, - 'isVertical': instance.isVertical, - 'error': instance.error, - }; diff --git a/pubspec.yaml b/pubspec.yaml index 07b0c79..bea0525 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,17 +1,15 @@ name: embed_video_player description: A Flutter package for embedding video players from various sources (VK, YouTube, and generic iframes) using WebView. -version: 1.0.5 +version: 1.1.0 environment: - sdk: '>=3.6.0 <4.0.0' - flutter: "3.29.0" + sdk: '>=3.10.0 <4.0.0' + flutter: ">=3.38.0 < 4.0.0" dependencies: flutter: sdk: flutter dio: ^5.4.1 - freezed_annotation: ^2.4.1 - json_annotation: ^4.9.0 flutter_inappwebview: ^6.2.0-beta.2 flutter_inappwebview_platform_interface: ^1.4.0-beta.2 plugin_platform_interface: ^2.1.8 @@ -20,13 +18,7 @@ dev_dependencies: flutter_test: sdk: flutter mockito: ^5.4.4 - build_runner: ^2.4.8 - flutter_lints: ^5.0.0 - freezed: ^2.5.8 - json_serializable: ^6.7.1 + flutter_lints: ^6.0.0 flutter: uses-material-design: true - # This section identifies this Flutter project as a plugin project. - # The 'pluginClass' specifies the class (in Java, Kotlin, Swift, Objective-C, etc.) - # which should be registered in the plugin registry.