import 'dart:convert'; import 'package:animations/animations.dart'; import 'package:fikoyt_sistem/apps/uyar/core/services/kullanici_service.dart'; import 'package:fikoyt_ui/core/fiko_request.dart'; import 'package:fikoyt_ui/core/fikoyt_request_manager/fikoyt_request_engine.dart'; import 'package:fikoyt_ui/fikoyt_ui.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart' hide FormData, MultipartFile; import 'package:dio/dio.dart' as Dio; class UyarService extends GetxService { KullaniciService logicKullanici = Get.put(KullaniciService()); /** */ Rx aktifKullanici = Rx(null); late FikoYTRequestEngine girisIstek; @override void onInit() { super.onInit(); girisIstek = FikoYTRequestEngine>( command: "FikoYT.sistem.giris.yap", parameters: {"x": 1}, retryCount: 2, onEkOlsun: true, autoIsBusy: false, ) .onStart((self) { self.isBusy.value = true; // print("🚀 İşlem baslatıldı"); }) // .onProgress((e) => print("⏳ ${e.requestProgress?.percent}%")) .onResult((self, sonuc) { toastification.dismissAll(delayForAnimation: true); aktifKullanici.value = sonuc.result?["sonuc"]; FikoYTCoreService.serviceSettings.socketDataMiddleWare = {"kullanici_kimlik": aktifKullanici.value?["_id"]}; FikoYTCoreService.socket.disconnect(); FikoYTCoreService.socket.connect(); /// Giriş Başarılı toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.success, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text( "Sn. ${sonuc.result?['sonuc']?['isim'] ?? ''} ${sonuc.result?['sonuc']?['soyIsim'] ?? ''} Girişiniz Yapıldı.", ), alignment: Alignment.topRight, margin: EdgeInsets.only(top: 32, right: 20), autoCloseDuration: const Duration(seconds: 4), borderRadius: BorderRadius.circular(4.0), // boxShadow: lowModeShadow, showProgressBar: false, dragToClose: true, applyBlurEffect: true, ); FikoYTCoreService.navigatorKey.currentContext?.vRouter.to("/uyar/uye/ana-sayfa"); }) .onError((self, hatalar) { toastification.dismissAll(delayForAnimation: true); toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.error, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text("Girilen Bilgileri Kontrol Ediniz."), alignment: Alignment.topRight, margin: EdgeInsets.only(top: 32, right: 20), autoCloseDuration: const Duration(seconds: 4), borderRadius: BorderRadius.circular(4.0), // boxShadow: lowModeShadow, showProgressBar: false, dragToClose: true, applyBlurEffect: true, ); }) // .onError((e) => print("❌ Hatalar: ${e.list.map((x) => x.message).join(", ")}")) .onDone((self) async { await Future.delayed(Duration(seconds: 1)); self.isBusy.value = false; // print("🏁 İşlem tamam"); }); } girisYap(BuildContext context, {required String ad, required String parola}) async { var formData = Dio.FormData(); formData.fields.add(MapEntry("req_body", jsonEncode({"kullaniciAdi": ad, "parola": parola}).toString())); /** */ if (girisIstek.isBusy.value) return; girisIstek.beforeSendList.clear(); girisIstek.beforeSend((self) async { girisIstek.parameters = formData; }); girisIstek.startWithQueue(); return; /** */ istek_yap(command: 'FikoYT.sistem.giris.yap', parameters: formData) .listen((sonuc) async { if (sonuc.type == FikoYTRequestType.RESPONDED) { toastification.dismissAll(delayForAnimation: true); aktifKullanici.value = sonuc.result?["sonuc"]; FikoYTCoreService.serviceSettings.socketDataMiddleWare = {"kullanici_kimlik": aktifKullanici.value?["_id"]}; FikoYTCoreService.socket.disconnect(); FikoYTCoreService.socket.connect(); /// Giriş Başarılı toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.success, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text( "Sn. ${sonuc.result?['sonuc']?['isim'] ?? ''} ${sonuc.result?['sonuc']?['soyIsim'] ?? ''} Girişiniz Yapıldı.", ), alignment: Alignment.topRight, margin: EdgeInsets.only(top: 32, right: 20), autoCloseDuration: const Duration(seconds: 4), borderRadius: BorderRadius.circular(4.0), // boxShadow: lowModeShadow, showProgressBar: false, dragToClose: true, applyBlurEffect: true, ); context.vRouter.to("/uyar/uye/ana-sayfa"); } }) /** */ .onError((hata) async { toastification.dismissAll(delayForAnimation: true); /// Giriş Başarılı toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.error, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text("Girilen Bilgileri Kontrol Ediniz."), alignment: Alignment.topRight, margin: EdgeInsets.only(top: 32, right: 20), autoCloseDuration: const Duration(seconds: 4), borderRadius: BorderRadius.circular(4.0), // boxShadow: lowModeShadow, showProgressBar: false, dragToClose: true, applyBlurEffect: true, ); }); } cikisYap(BuildContext context) { istek_yap(command: 'FikoYT.sistem.cikis.yap') .listen((sonuc) async { if (sonuc.type == FikoYTRequestType.RESPONDED) { toastification.dismissAll(delayForAnimation: true); aktifKullanici.value = null; FikoYTCoreService.serviceSettings.socketDataMiddleWare = {"kullanici_kimlik": null}; FikoYTCoreService.socket.disconnect(); FikoYTCoreService.socket.connect(); /// Giriş Başarılı toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.info, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text("Çıkışınız Yapıldı."), alignment: Alignment.topRight, margin: EdgeInsets.only(top: 32, right: 20), autoCloseDuration: const Duration(seconds: 4), borderRadius: BorderRadius.circular(4.0), // boxShadow: lowModeShadow, showProgressBar: false, dragToClose: true, applyBlurEffect: true, ); context.vRouter.to("/uyar/kisi/ana-sayfa"); FikoYTCoreService.ioEmit("FikoYT.sistem.io.cihaz.baglandi", {}); } }) /** */ .onError((hata) async { toastification.dismissAll(delayForAnimation: true); FikoYTCoreService.ioEmit("FikoYT.sistem.io.cihaz.baglandi", {}); }); } Duration openContainerDuration = Duration(milliseconds: 750); animasyonluWidgetAc({ String? ozelId, required Widget Function(BuildContext, void Function()) mevcutWidget, required Widget Function(BuildContext, void Function({Never returnValue})) acilacakWidget, Color closedColor = Colors.transparent, Color openColor = Colors.white, Color? middleColor = Colors.transparent, double closedElevation = 0.0, double openElevation = 0.0, ShapeBorder closedShape = const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(0.0))), ShapeBorder openShape = const RoundedRectangleBorder(), void Function(Object?)? onClosed, bool tappable = false, Duration? transitionDuration, ContainerTransitionType transitionType = ContainerTransitionType.fade, bool useRootNavigator = false, RouteSettings? routeSettings, Clip clipBehavior = Clip.antiAlias, }) { // FikoYTRotaGecmis? kyt = rotalar.firstWhereOrNull((item) => item.ozelId == (ozelId ?? routeSettings?.name)); // if (kyt != null) { // return kyt.konteynir; // } // for (var i = rotalar.length - 1; i > 0; i--) { // FikoYTRotaGecmis element = rotalar[i]; // if (element.rota == (ozelId ?? routeSettings?.name)) { // return element.konteynir; // } // } void Function({Never returnValue})? closeAction; void Function()? openAction; OpenContainer rslt = OpenContainer( // routeSettings: routeSettings, useRootNavigator: useRootNavigator, closedColor: closedColor, closedElevation: closedElevation, middleColor: middleColor, openElevation: openElevation, tappable: tappable, closedShape: closedShape, transitionDuration: transitionDuration ?? openContainerDuration, transitionType: transitionType, closedBuilder: (context, action) { openAction = action; return GestureDetector(onTap: action, child: mevcutWidget(context, action)); }, openBuilder: (context, action) { closeAction = action; return acilacakWidget(context, action); }, onClosed: (data) { // rotalar.removeWhere((item) => item.ozelId == (ozelId ?? routeSettings?.name)); if (onClosed != null) onClosed(data); }, ); // rotalar.add( // FikoYTRotaGecmis( // ozelId: ozelId ?? routeSettings?.name ?? Random(5000).toString(), // rota: ozelId ?? routeSettings?.name ?? Random(5000).toString(), // konteynir: rslt, // closeAction: openAction, // openAction: closeAction, // ), // ); // print(rotalar.length); return rslt; } }