import 'dart:convert'; import 'package:fikoyt_sistem/apps/uyar/core/services/uyar_service.dart'; import 'package:fikoyt_ui/core/fikoyt_request_manager/fikoyt_request_engine.dart'; import 'package:fikoyt_ui/fikoyt_ui.dart'; import 'package:fikoyt_ui/ui/fikoyt_card.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import "package:dio/dio.dart" as Dio; class KullaniciItem extends StatefulWidget { KullaniciItem({super.key, this.uye}); Map? uye; @override _KullaniciItemState createState() => _KullaniciItemState(); } class _KullaniciItemState extends State { final UyarService uyarService = Get.put(UyarService()); late FikoYTRequestEngine silIstek; late FikoYTRequestEngine silGeriAlIstek; @override void initState() { silIstek = FikoYTRequestEngine>( command: "/uyar/admin/kullanicilar/sil", // parameters: {"x": 1}, retryCount: 2, onEkOlsun: false, autoIsBusy: false, ) .onStart((self) { self.isBusy.value = true; // print("🚀 İşlem baslatıldı"); }) // .onProgress((e) => print("⏳ ${e.requestProgress?.percent}%")) .onResult((self, e) { // kullanicilar.value = e.result; widget.uye?['silindi'] = true; toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.success, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text("Üye Başarılı Şekilde Deaktif Edilmiştir."), 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; }) .onError((self, e) async { await Future.delayed(Duration(seconds: 1)); self.isBusy.value = false; toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.error, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text(e.list.map((x) => x.message).join("\t\n")), 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, ); // print("❌ Hatalar: ${e.list.map((x) => x.message).join(", ")}"); }); /** */ silGeriAlIstek = FikoYTRequestEngine>( command: "/uyar/admin/kullanicilar/sil-geri-al", // parameters: {"x": 1}, retryCount: 2, onEkOlsun: false, autoIsBusy: false, ) .onStart((self) { self.isBusy.value = true; // print("🚀 İşlem baslatıldı"); }) // .onProgress((e) => print("⏳ ${e.requestProgress?.percent}%")) .onResult((self, e) { // kullanicilar.value = e.result; widget.uye?['silindi'] = false; toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.success, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text("Üye Başarılı Şekilde Tekrar Aktif Edilmiştir."), 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; }) .onError((self, e) async { await Future.delayed(Duration(seconds: 1)); self.isBusy.value = false; toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.error, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text(e.list.map((x) => x.message).join("\t\n")), 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, ); // print("❌ Hatalar: ${e.list.map((x) => x.message).join(", ")}"); }); super.initState(); } @override Widget build(BuildContext context) { final String imageUrl = "https://fikoyt.com:9000/fapiv1/fikoyt.com.FikoYT.sistem.kullanici.${widget.uye?['_id']?.toString()}.profilResmi?boyut=128x?&t=0.8143431303498987"; final String fullName = "${widget.uye?['isim'] ?? ""} ${widget.uye?['soyIsim'] ?? ""}"; final bool isSuperAdmin = ((widget.uye?['yetkiler'] as List?) ?? []).contains("Süper Yönetici"); final bool aktifKullaniciIsSuperAdmin = ((uyarService.aktifKullanici.value?['yetkiler'] as List?) ?? []).contains( "Süper Yönetici", ); return FikoYTCard( theme: FikoYTCardTheme( elevation: 4, backgroundColor: widget.uye?['silindi'] != true ? Colors.white : Colors.red.shade200, borderColor: Colors.grey, padding: EdgeInsets.all(5), radius: 5, boxConstraints: BoxConstraints(maxWidth: 160, maxHeight: 170, minHeight: 150), ), children: [ Stack( alignment: Alignment.topLeft, children: [ Row( children: [ Spacer(), if (aktifKullaniciIsSuperAdmin) Obx( () => SizedBox( key: const ValueKey('loading'), height: 24, width: 24, child: AnimatedSwitcher( duration: const Duration(milliseconds: 500), transitionBuilder: (Widget child, Animation animation) { return FadeTransition( opacity: animation, child: ScaleTransition(scale: animation, child: child), ); }, child: silIstek.isBusy.value ? const CircularProgressIndicator(color: Colors.blue, padding: EdgeInsets.all(3)) : widget.uye?['silindi'] != true ? FikoYTButton( text: "🗑", tema: FikoYTButtonTheme( textColor: Colors.white, backgroundColor: Colors.transparent, // fontWeight: FontWeight.w700, edgePadding: EdgeInsets.all(0), radius: 0, borderColor: Colors.transparent, // elevation: 3, fontSize: 12, ), onPressed: () async { if (silIstek.isBusy.value) return; silIstek.beforeSendList.clear(); silIstek.beforeSend((self) async { final yeniFormData = Dio.FormData.fromMap({}); yeniFormData.fields.add(MapEntry("req_body", jsonEncode({"kid": widget.uye?['_id']}))); // ‼️ Her seferinde TAZE formData ata self.parameters = yeniFormData; }); silIstek.startWithQueue(); }, ) : FikoYTButton( text: "🔙", tema: FikoYTButtonTheme( textColor: Colors.white, backgroundColor: Colors.transparent, // fontWeight: FontWeight.w700, edgePadding: EdgeInsets.all(0), radius: 0, borderColor: Colors.transparent, // elevation: 3, fontSize: 12, ), onPressed: () async { if (silIstek.isBusy.value) return; silIstek.beforeSendList.clear(); silIstek.beforeSend((self) async { final yeniFormData = Dio.FormData.fromMap({}); yeniFormData.fields.add(MapEntry("req_body", jsonEncode({"kid": widget.uye?['_id']}))); // ‼️ Her seferinde TAZE formData ata self.parameters = yeniFormData; }); silIstek.startWithQueue(); }, ), ), ), ), ], ), Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, children: [ FikoytOvalResim( resimUrl: imageUrl, tema: FikoYTOvalResimTheme(borderColor: Colors.blue, radius: 42, spacing: 7), ), Center( child: FikoYTButton( text: fullName, tema: FikoYTButtonTheme( fontSize: 12, fontWeight: FontWeight.w600, edgePadding: EdgeInsets.all(0), radius: 0, backgroundColor: Colors.transparent, textColor: Colors.black87, ), ), ), SizedBox( height: 36, child: SingleChildScrollView( scrollDirection: Axis.horizontal, physics: BouncingScrollPhysics(), child: Row( spacing: 2, children: [ if (isSuperAdmin) FikoYTButton( text: "👑", tema: FikoYTButtonTheme( fontSize: 14, edgePadding: EdgeInsets.all(3), radius: 5, backgroundColor: Colors.transparent, ), onPressed: () { // context.vRouter.to("/uyar/uye/kullanici/arkadaslar"); }, ), ], ), ), ), ], ), ], ), ], ); } }