feat : module page

This commit is contained in:
2025-08-27 11:56:29 +03:30
parent 5ffda97e54
commit d3e5ab7d61
31 changed files with 1313 additions and 93 deletions

View File

@@ -0,0 +1,15 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'slider_model.freezed.dart';
part 'slider_model.g.dart';
@freezed
abstract class SliderModel with _$SliderModel {
const factory SliderModel({
List<String>? up,
List<String>? down,
}) = _SliderModel;
factory SliderModel.fromJson(Map<String, dynamic> json) =>
_$SliderModelFromJson(json);
}

View File

@@ -0,0 +1,296 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// 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 'slider_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$SliderModel {
List<String>? get up; List<String>? get down;
/// Create a copy of SliderModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$SliderModelCopyWith<SliderModel> get copyWith => _$SliderModelCopyWithImpl<SliderModel>(this as SliderModel, _$identity);
/// Serializes this SliderModel to a JSON map.
Map<String, dynamic> toJson();
@override
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));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(up),const DeepCollectionEquality().hash(down));
@override
String toString() {
return 'SliderModel(up: $up, down: $down)';
}
}
/// @nodoc
abstract mixin class $SliderModelCopyWith<$Res> {
factory $SliderModelCopyWith(SliderModel value, $Res Function(SliderModel) _then) = _$SliderModelCopyWithImpl;
@useResult
$Res call({
List<String>? up, List<String>? down
});
}
/// @nodoc
class _$SliderModelCopyWithImpl<$Res>
implements $SliderModelCopyWith<$Res> {
_$SliderModelCopyWithImpl(this._self, this._then);
final SliderModel _self;
final $Res Function(SliderModel) _then;
/// Create a copy of SliderModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? up = freezed,Object? down = freezed,}) {
return _then(_self.copyWith(
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>?,
));
}
}
/// Adds pattern-matching-related methods to [SliderModel].
extension SliderModelPatterns on SliderModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _SliderModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _SliderModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _SliderModel value) $default,){
final _that = this;
switch (_that) {
case _SliderModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _SliderModel value)? $default,){
final _that = this;
switch (_that) {
case _SliderModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<String>? up, List<String>? down)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _SliderModel() when $default != null:
return $default(_that.up,_that.down);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<String>? up, List<String>? down) $default,) {final _that = this;
switch (_that) {
case _SliderModel():
return $default(_that.up,_that.down);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<String>? up, List<String>? down)? $default,) {final _that = this;
switch (_that) {
case _SliderModel() when $default != null:
return $default(_that.up,_that.down);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _SliderModel implements SliderModel {
const _SliderModel({final List<String>? up, final List<String>? down}): _up = up,_down = down;
factory _SliderModel.fromJson(Map<String, dynamic> json) => _$SliderModelFromJson(json);
final List<String>? _up;
@override List<String>? get up {
final value = _up;
if (value == null) return null;
if (_up is EqualUnmodifiableListView) return _up;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
final List<String>? _down;
@override List<String>? get down {
final value = _down;
if (value == null) return null;
if (_down is EqualUnmodifiableListView) return _down;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
/// Create a copy of SliderModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$SliderModelCopyWith<_SliderModel> get copyWith => __$SliderModelCopyWithImpl<_SliderModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$SliderModelToJson(this, );
}
@override
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));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_up),const DeepCollectionEquality().hash(_down));
@override
String toString() {
return 'SliderModel(up: $up, down: $down)';
}
}
/// @nodoc
abstract mixin class _$SliderModelCopyWith<$Res> implements $SliderModelCopyWith<$Res> {
factory _$SliderModelCopyWith(_SliderModel value, $Res Function(_SliderModel) _then) = __$SliderModelCopyWithImpl;
@override @useResult
$Res call({
List<String>? up, List<String>? down
});
}
/// @nodoc
class __$SliderModelCopyWithImpl<$Res>
implements _$SliderModelCopyWith<$Res> {
__$SliderModelCopyWithImpl(this._self, this._then);
final _SliderModel _self;
final $Res Function(_SliderModel) _then;
/// Create a copy of SliderModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? up = freezed,Object? down = freezed,}) {
return _then(_SliderModel(
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>?,
));
}
}
// dart format on

View File

@@ -0,0 +1,15 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'slider_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_SliderModel _$SliderModelFromJson(Map<String, dynamic> json) => _SliderModel(
up: (json['up'] as List<dynamic>?)?.map((e) => e as String).toList(),
down: (json['down'] as List<dynamic>?)?.map((e) => e as String).toList(),
);
Map<String, dynamic> _$SliderModelToJson(_SliderModel instance) =>
<String, dynamic>{'up': instance.up, 'down': instance.down};

View File

@@ -1,38 +1,90 @@
import 'package:flutter/material.dart';
import 'package:rasadyar_app/data/model/response/slider/slider_model.dart';
import 'package:rasadyar_app/presentation/routes/app_pages.dart';
import 'package:rasadyar_core/core.dart';
class ModulesLogic extends GetxController {
TokenStorageService tokenService = Get.find<TokenStorageService>();
SliderLogic upSlider = Get.find<SliderLogic>(tag: "up");
SliderLogic downSlider = Get.find<SliderLogic>(tag: "down");
RxBool isLoading = false.obs;
List<ModuleModel> moduleList = [
ModuleModel(title: 'بازرسی', icon: Assets.icons.inspection.path, module: Module.inspection),
ModuleModel(title: 'دام', icon: Assets.icons.liveStock.path, module: Module.liveStocks),
ModuleModel(title: 'مرغ', icon: Assets.icons.liveStock.path, module: Module.chicken),
ModuleModel(
title: 'رصدطیور',
icon: Assets.icons.rasadToyor.path,
module: Module.chicken,
borderColor: Color(0xFF4665AF),
backgroundColor: Color(0xFFECEEF2),
titleColor: Color(0xFF4665AF),
),
ModuleModel(
title: 'رصدام',
icon: Assets.icons.rasadDam.path,
module: Module.liveStocks,
borderColor: Color(0xFFD7A972),
backgroundColor: Color(0xFFF4F1EF),
titleColor: Color(0xFF7F7F7F),
),
ModuleModel(
title: 'رصدبان',
icon: Assets.icons.rasadBan.path,
module: Module.inspection,
borderColor: Color(0xFF014856),
backgroundColor: Color(0xFFE9EDED),
titleColor: Color(0xFF014856),
),
ModuleModel(
title: 'رصدبار',
icon: Assets.icons.rasadBar.path,
borderColor: Color(0xFFF37021),
backgroundColor: Color(0xFFFFECE1),
titleColor: Color(0xFFF37021),
),
ModuleModel(
title: 'رصدبات',
icon: Assets.icons.rasadBot.path,
borderColor: Color(0xFF4A148C),
backgroundColor: Color(0xFFEDEAF0),
titleColor: Color(0xFF4A148C),
),
ModuleModel(
title: 'رصدنان',
icon: Assets.icons.rasadNan.path,
borderColor: Color(0xFFD7A972),
backgroundColor: Color(0xFFF4F2EA),
titleColor: Color(0xFF8E8E8E),
),
];
RxnInt selectedIndex = RxnInt(null);
@override
void onReady() {
super.onReady();
void onInit() {
super.onInit();
getSliders();
}
@override
void onClose() {
super.onClose();
}
void saveModule(Module module) {
tokenService.saveModule(module);
tokenService.appModule.value = module;
}
void onTapCard(Module module, int index) async {
isLoading.value = !isLoading.value;
void onTapCard(Module? module, int index) async {
if (module == null) {
Get.snackbar("بزودی", "این ماژول به زودی اضافه می‌شود", snackPosition: SnackPosition.BOTTOM);
} else {
_goToModule(module, index);
}
}
void _goToModule(Module module, int index) async {
selectedIndex.value = index;
await Future.delayed(Duration(milliseconds: 200)); // Simulate loading delay
navigateToModule(module);
await Future.delayed(Duration(milliseconds: 300));
selectedIndex.value = null;
saveModule(module);
await navigateToModule(module);
}
Future<void> navigateToModule(Module module) async {
@@ -44,4 +96,24 @@ class ModulesLogic extends GetxController {
isLoading.value = !isLoading.value;
Get.toNamed(target.key, arguments: module);
}
Future<void> getSliders() async {
var dio = Dio();
dio.interceptors.add(
PrettyDioLogger(
request: true,
enabled: true,
requestHeader: true,
responseHeader: true,
requestBody: true,
responseBody: true,
),
);
var res = await dio.get("https://miran.storage.c2.liara.space/app/urllapp.json");
if (res.statusCode == 200) {
SliderModel sliderModel = SliderModel.fromJson(res.data);
upSlider.onSuccess(sliderModel.up ?? []);
downSlider.onSuccess(sliderModel.down ?? []);
}
}
}

View File

@@ -11,7 +11,13 @@ class ModulesPage extends GetView<ModulesLogic> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('انتخاب سامانه', style: AppFonts.yekan18.copyWith(color: Colors.white)),
title: Row(
spacing: 5.w,
children: [
Text('سامانه جامع رصدیار', style: AppFonts.yekan18Bold.copyWith(color: Colors.white)),
Assets.logos.finalLogo.image(width: 40.w, height: 40.h),
],
),
centerTitle: true,
backgroundColor: AppColor.blueNormal,
),
@@ -19,23 +25,40 @@ class ModulesPage extends GetView<ModulesLogic> {
fit: StackFit.expand,
alignment: Alignment.center,
children: [
GridView.builder(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 20),
itemBuilder: (context, index) {
final module = controller.moduleList[index];
return CardIcon(
title: module.title,
icon: module.icon,
onTap: () => controller.onTapCard(module.module, index),
);
},
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 10,
crossAxisSpacing: 10,
Positioned.fill(
child: Column(
children: [
SizedBox(height: 24.h),
SliderWidget(widgetTag: "up"),
Expanded(
child: GridView.builder(
padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 24.h),
itemBuilder: (context, index) {
final module = controller.moduleList[index];
return CardIcon(
title: module.title,
icon: module.icon,
borderColor: module.borderColor,
backgroundColor: module.backgroundColor,
titleColor: module.titleColor,
onTap: () => controller.onTapCard(module.module, index),
);
},
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 24.h,
crossAxisSpacing: 16.w,
),
physics: BouncingScrollPhysics(),
itemCount: controller.moduleList.length,
),
),
SliderWidget(height: 160, widgetTag: "down"),
SizedBox(height: 30.h),
],
),
physics: BouncingScrollPhysics(),
itemCount: controller.moduleList.length,
),
ObxValue((loading) {
if (!controller.isLoading.value) return SizedBox.shrink();

View File

@@ -25,7 +25,12 @@ sealed class AppPages {
GetPage(
name: AppPaths.moduleList,
page: () => ModulesPage(),
binding: BindingsBuilder.put(() => ModulesLogic()),
binding: BindingsBuilder(() {
Get.lazyPut(() => SliderLogic(), tag: "up");
Get.lazyPut(() => SliderLogic(), tag: "down");
Get.put(ModulesLogic());
}),
),
GetPage(
@@ -35,35 +40,33 @@ sealed class AppPages {
),
...InspectionPages.pages,
...LiveStockPages.pages,
...ChickenPages.pages,
];
}
Map<String, Future<void>?> getTargetModule(Module? value) {
switch (value) {
case Module.inspection:
return {InspectionRoutes.init:setupInspectionDI()};
return {InspectionRoutes.init: setupInspectionDI()};
case Module.liveStocks:
return {LiveStockRoutes.init: setupLiveStockDI()};
case Module.chicken:
return {ChickenRoutes.init : setupChickenDI()};
return {ChickenRoutes.init: setupChickenDI()};
default:
return {AppPaths.moduleList : null};
return {AppPaths.moduleList: null};
}
}
Map<String, Future<void>?> getAuthTargetPage(Module? value) {
switch (value) {
case Module.inspection:
return {InspectionRoutes.auth:setupInspectionDI()};
return {InspectionRoutes.auth: setupInspectionDI()};
case Module.liveStocks:
return {LiveStockRoutes.auth: setupLiveStockDI()};
case Module.chicken:
return {ChickenRoutes.auth : setupChickenDI()};
return {ChickenRoutes.auth: setupChickenDI()};
default:
return {AppPaths.moduleList : null};
return {AppPaths.moduleList: null};
}
}