feat : module page
This commit is contained in:
@@ -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 ?? []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user