feat : latest News in module page

This commit is contained in:
2025-09-01 10:58:17 +03:30
parent 5af5d63a1e
commit c2f5e36fd7
5 changed files with 44 additions and 35 deletions

View File

@@ -5,11 +5,7 @@ part 'slider_model.g.dart';
@freezed @freezed
abstract class SliderModel with _$SliderModel { abstract class SliderModel with _$SliderModel {
const factory SliderModel({ const factory SliderModel({List<String>? up, List<String>? down, String? middle}) = _SliderModel;
List<String>? up,
List<String>? down,
}) = _SliderModel;
factory SliderModel.fromJson(Map<String, dynamic> json) => factory SliderModel.fromJson(Map<String, dynamic> json) => _$SliderModelFromJson(json);
_$SliderModelFromJson(json);
} }

View File

@@ -15,7 +15,7 @@ T _$identity<T>(T value) => value;
/// @nodoc /// @nodoc
mixin _$SliderModel { mixin _$SliderModel {
List<String>? get up; List<String>? get down; List<String>? get up; List<String>? get down; String? get middle;
/// Create a copy of SliderModel /// Create a copy of SliderModel
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false) @JsonKey(includeFromJson: false, includeToJson: false)
@@ -28,16 +28,16 @@ $SliderModelCopyWith<SliderModel> get copyWith => _$SliderModelCopyWithImpl<Slid
@override @override
bool operator ==(Object other) { bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is SliderModel&&const DeepCollectionEquality().equals(other.up, up)&&const DeepCollectionEquality().equals(other.down, down)); return identical(this, other) || (other.runtimeType == runtimeType&&other is SliderModel&&const DeepCollectionEquality().equals(other.up, up)&&const DeepCollectionEquality().equals(other.down, down)&&(identical(other.middle, middle) || other.middle == middle));
} }
@JsonKey(includeFromJson: false, includeToJson: false) @JsonKey(includeFromJson: false, includeToJson: false)
@override @override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(up),const DeepCollectionEquality().hash(down)); int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(up),const DeepCollectionEquality().hash(down),middle);
@override @override
String toString() { String toString() {
return 'SliderModel(up: $up, down: $down)'; return 'SliderModel(up: $up, down: $down, middle: $middle)';
} }
@@ -48,7 +48,7 @@ abstract mixin class $SliderModelCopyWith<$Res> {
factory $SliderModelCopyWith(SliderModel value, $Res Function(SliderModel) _then) = _$SliderModelCopyWithImpl; factory $SliderModelCopyWith(SliderModel value, $Res Function(SliderModel) _then) = _$SliderModelCopyWithImpl;
@useResult @useResult
$Res call({ $Res call({
List<String>? up, List<String>? down List<String>? up, List<String>? down, String? middle
}); });
@@ -65,11 +65,12 @@ class _$SliderModelCopyWithImpl<$Res>
/// Create a copy of SliderModel /// Create a copy of SliderModel
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? up = freezed,Object? down = freezed,}) { @pragma('vm:prefer-inline') @override $Res call({Object? up = freezed,Object? down = freezed,Object? middle = freezed,}) {
return _then(_self.copyWith( return _then(_self.copyWith(
up: freezed == up ? _self.up : up // ignore: cast_nullable_to_non_nullable up: freezed == up ? _self.up : up // ignore: cast_nullable_to_non_nullable
as List<String>?,down: freezed == down ? _self.down : down // ignore: cast_nullable_to_non_nullable as List<String>?,down: freezed == down ? _self.down : down // ignore: cast_nullable_to_non_nullable
as List<String>?, as List<String>?,middle: freezed == middle ? _self.middle : middle // ignore: cast_nullable_to_non_nullable
as String?,
)); ));
} }
@@ -154,10 +155,10 @@ return $default(_that);case _:
/// } /// }
/// ``` /// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<String>? up, List<String>? down)? $default,{required TResult orElse(),}) {final _that = this; @optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<String>? up, List<String>? down, String? middle)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) { switch (_that) {
case _SliderModel() when $default != null: case _SliderModel() when $default != null:
return $default(_that.up,_that.down);case _: return $default(_that.up,_that.down,_that.middle);case _:
return orElse(); return orElse();
} }
@@ -175,10 +176,10 @@ return $default(_that.up,_that.down);case _:
/// } /// }
/// ``` /// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<String>? up, List<String>? down) $default,) {final _that = this; @optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<String>? up, List<String>? down, String? middle) $default,) {final _that = this;
switch (_that) { switch (_that) {
case _SliderModel(): case _SliderModel():
return $default(_that.up,_that.down);case _: return $default(_that.up,_that.down,_that.middle);case _:
throw StateError('Unexpected subclass'); throw StateError('Unexpected subclass');
} }
@@ -195,10 +196,10 @@ return $default(_that.up,_that.down);case _:
/// } /// }
/// ``` /// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<String>? up, List<String>? down)? $default,) {final _that = this; @optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<String>? up, List<String>? down, String? middle)? $default,) {final _that = this;
switch (_that) { switch (_that) {
case _SliderModel() when $default != null: case _SliderModel() when $default != null:
return $default(_that.up,_that.down);case _: return $default(_that.up,_that.down,_that.middle);case _:
return null; return null;
} }
@@ -210,7 +211,7 @@ return $default(_that.up,_that.down);case _:
@JsonSerializable() @JsonSerializable()
class _SliderModel implements SliderModel { class _SliderModel implements SliderModel {
const _SliderModel({final List<String>? up, final List<String>? down}): _up = up,_down = down; const _SliderModel({final List<String>? up, final List<String>? down, this.middle}): _up = up,_down = down;
factory _SliderModel.fromJson(Map<String, dynamic> json) => _$SliderModelFromJson(json); factory _SliderModel.fromJson(Map<String, dynamic> json) => _$SliderModelFromJson(json);
final List<String>? _up; final List<String>? _up;
@@ -231,6 +232,7 @@ class _SliderModel implements SliderModel {
return EqualUnmodifiableListView(value); return EqualUnmodifiableListView(value);
} }
@override final String? middle;
/// Create a copy of SliderModel /// Create a copy of SliderModel
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@@ -245,16 +247,16 @@ Map<String, dynamic> toJson() {
@override @override
bool operator ==(Object other) { bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _SliderModel&&const DeepCollectionEquality().equals(other._up, _up)&&const DeepCollectionEquality().equals(other._down, _down)); return identical(this, other) || (other.runtimeType == runtimeType&&other is _SliderModel&&const DeepCollectionEquality().equals(other._up, _up)&&const DeepCollectionEquality().equals(other._down, _down)&&(identical(other.middle, middle) || other.middle == middle));
} }
@JsonKey(includeFromJson: false, includeToJson: false) @JsonKey(includeFromJson: false, includeToJson: false)
@override @override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_up),const DeepCollectionEquality().hash(_down)); int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_up),const DeepCollectionEquality().hash(_down),middle);
@override @override
String toString() { String toString() {
return 'SliderModel(up: $up, down: $down)'; return 'SliderModel(up: $up, down: $down, middle: $middle)';
} }
@@ -265,7 +267,7 @@ abstract mixin class _$SliderModelCopyWith<$Res> implements $SliderModelCopyWith
factory _$SliderModelCopyWith(_SliderModel value, $Res Function(_SliderModel) _then) = __$SliderModelCopyWithImpl; factory _$SliderModelCopyWith(_SliderModel value, $Res Function(_SliderModel) _then) = __$SliderModelCopyWithImpl;
@override @useResult @override @useResult
$Res call({ $Res call({
List<String>? up, List<String>? down List<String>? up, List<String>? down, String? middle
}); });
@@ -282,11 +284,12 @@ class __$SliderModelCopyWithImpl<$Res>
/// Create a copy of SliderModel /// Create a copy of SliderModel
/// with the given fields replaced by the non-null parameter values. /// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? up = freezed,Object? down = freezed,}) { @override @pragma('vm:prefer-inline') $Res call({Object? up = freezed,Object? down = freezed,Object? middle = freezed,}) {
return _then(_SliderModel( return _then(_SliderModel(
up: freezed == up ? _self._up : up // ignore: cast_nullable_to_non_nullable up: freezed == up ? _self._up : up // ignore: cast_nullable_to_non_nullable
as List<String>?,down: freezed == down ? _self._down : down // ignore: cast_nullable_to_non_nullable as List<String>?,down: freezed == down ? _self._down : down // ignore: cast_nullable_to_non_nullable
as List<String>?, as List<String>?,middle: freezed == middle ? _self.middle : middle // ignore: cast_nullable_to_non_nullable
as String?,
)); ));
} }

View File

@@ -9,7 +9,12 @@ part of 'slider_model.dart';
_SliderModel _$SliderModelFromJson(Map<String, dynamic> json) => _SliderModel( _SliderModel _$SliderModelFromJson(Map<String, dynamic> json) => _SliderModel(
up: (json['up'] as List<dynamic>?)?.map((e) => e as String).toList(), up: (json['up'] as List<dynamic>?)?.map((e) => e as String).toList(),
down: (json['down'] as List<dynamic>?)?.map((e) => e as String).toList(), down: (json['down'] as List<dynamic>?)?.map((e) => e as String).toList(),
middle: json['middle'] as String?,
); );
Map<String, dynamic> _$SliderModelToJson(_SliderModel instance) => Map<String, dynamic> _$SliderModelToJson(_SliderModel instance) =>
<String, dynamic>{'up': instance.up, 'down': instance.down}; <String, dynamic>{
'up': instance.up,
'down': instance.down,
'middle': instance.middle,
};

View File

@@ -7,6 +7,7 @@ class ModulesLogic extends GetxController {
TokenStorageService tokenService = Get.find<TokenStorageService>(); TokenStorageService tokenService = Get.find<TokenStorageService>();
SliderLogic upSlider = Get.find<SliderLogic>(tag: "up"); SliderLogic upSlider = Get.find<SliderLogic>(tag: "up");
SliderLogic downSlider = Get.find<SliderLogic>(tag: "down"); SliderLogic downSlider = Get.find<SliderLogic>(tag: "down");
RxnString latestNews = RxnString();
RxBool isLoading = false.obs; RxBool isLoading = false.obs;
List<ModuleModel> moduleList = [ List<ModuleModel> moduleList = [
@@ -125,6 +126,7 @@ class ModulesLogic extends GetxController {
SliderModel sliderModel = SliderModel.fromJson(res.data); SliderModel sliderModel = SliderModel.fromJson(res.data);
upSlider.onSuccess(sliderModel.up ?? []); upSlider.onSuccess(sliderModel.up ?? []);
downSlider.onSuccess(sliderModel.down ?? []); downSlider.onSuccess(sliderModel.down ?? []);
latestNews.value = sliderModel.middle;
} }
} }
} }

View File

@@ -84,15 +84,18 @@ class ModulesPage extends GetView<ModulesLogic> {
height: 1.90, height: 1.90,
), ),
), ),
Text( ObxValue(
'اخبار مربوط به جوجه ریزی استان از آخرین روند مطلع شوید اخبار مربوط به جوجه ریزی استان از ', (data) => Text(
maxLines: 2, data.value ??
'اخبار مربوط به جوجه ریزی استان از آخرین روند مطلع شوید...',
style: AppFonts.yekan12.copyWith( maxLines: 2,
color: Color(0xFF5B5B5B), style: AppFonts.yekan12.copyWith(
height: 1.5, color: Color(0xFF5B5B5B),
overflow: TextOverflow.ellipsis, height: 1.5,
overflow: TextOverflow.ellipsis,
),
), ),
controller.latestNews,
), ),
], ],
), ),