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 ?? []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user