import 'package:fikoyt_akcali_v1/apps/finans/core/models/finans.model.dart'; import 'package:fikoyt_akcali_v1/apps/finans/core/services/finans.servis.dart'; import 'package:fikoyt_akcali_v1/apps/finans/core/services/kategoriler_service.dart'; import 'package:fikoyt_akcali_v1/apps/finans/uye/kategoriler/kategori-ekle.dart'; import 'package:fikoyt_akcali_v1/apps/finans/uye/kategoriler/kategori-item.dart'; import 'package:fikoyt_akcali_v1/core/widgets/header_widget/header_widget.dart'; import 'package:fikoyt_akcali_v1/core/widgets/uygulama_baslik/uygulama_baslik.dart'; import 'package:fikoyt_ui/fikoyt_ui.dart'; import 'package:fikoyt_ui/ui/fikoyt_card.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class SayfaKategori extends StatefulWidget { SayfaKategori({super.key, required this.kyt, this.animClose}); final Rx kyt; void Function({Never returnValue})? animClose; @override State createState() => _SayfaKategoriState(); } class _SayfaKategoriState extends State { FinansServis? finansServis = FikoYTCoreService.servisler.getServis(); KategorilerService? logicKategoriler; bool isOpenFab = false; final Map _lastPressTimes = {}; bool isSecondRun({Duration threshold = const Duration(milliseconds: 500)}) { final now = DateTime.now(); final lastPressTime = _lastPressTimes["a"]; if (lastPressTime != null && now.difference(lastPressTime) < threshold) { _lastPressTimes.remove("a"); // İkinci kez basıldığını belirledik, sıfırla return true; // 🚀 İkinci kez basıldı } _lastPressTimes["a"] = now; return false; // İlk basım } @override void initState() { super.initState(); finansServis = FikoYTCoreService.servisler.getServis(); logicKategoriler = Get.put(KategorilerService()); } @override Widget build(BuildContext context) { return FikoYTSliverApp( leading: UygulamaBaslikSol(), title: UygulamaBaslikOrta(altBaslik: "Kategori"), actions: [UygulamaBaslikSag()], drawer: finansServis?.solMenu.value, backgroundColor: Theme.of(context).extension()?.backgroundColor, appBarColor: Theme.of(context).extension()?.appBarColor?.withAlpha(230), headerExpandedHeight: 250, // stretchMaxHeight: 100, fullyStretchable: true, centerTitle: true, alwaysShowLeadingAndAction: true, alwaysShowTitle: true, curvedBodyRadius: 0, floatingActionButton: TusYayilmasiEngelleWidget( shouldBlockKey: (event) { if (event.logicalKey == LogicalKeyboardKey.goBack || event.logicalKey == LogicalKeyboardKey.goHome || event.logicalKey == LogicalKeyboardKey.allCandidates || event.logicalKey == LogicalKeyboardKey.cancel || event.logicalKey == LogicalKeyboardKey.browserBack || event.physicalKey == PhysicalKeyboardKey.escape || event.physicalKey == PhysicalKeyboardKey.exit || event.physicalKey == PhysicalKeyboardKey.browserBack || event.physicalKey == PhysicalKeyboardKey.close || event.physicalKey == PhysicalKeyboardKey.undo) { if (isSecondRun()) { return false; } return true; } return false; }, child: TapRegion( child: AnimatedContainer( alignment: Alignment.center, width: isOpenFab ? 150 : 60, height: isOpenFab ? 150 : 60, decoration: BoxDecoration( color: isOpenFab ? Theme.of(context).extension()?.cardBackgroundColor : Colors.white, borderRadius: BorderRadius.circular(isOpenFab ? 5 : 35), boxShadow: Theme.of(context).extension()?.boxShadow, ), duration: Duration(milliseconds: ((finansServis?.openContainerDuration ?? Duration.zero).inMilliseconds / 2).toInt()), // margin: !widget.isOpenFab ? EdgeInsets.zero : EdgeInsets.only(right: 30, bottom: 30), // curve: Curves.easeInOut, padding: EdgeInsets.all(5), child: AnimatedSwitcher( duration: finansServis?.openContainerDuration ?? Duration.zero, reverseDuration: Duration(milliseconds: 250), child: !isOpenFab ? FikoYTButton( text: "+", tema: FikoYTButtonTheme( textColor: Colors.blue, // fontWeight: FontWeight.w700, edgePadding: EdgeInsets.all(3), // borderColor: Colors.blueAccent, elevation: 3, fontSize: 36, ), ) : TusYayilmasiEngelleWidget( shouldBlockKey: (event) { if (event.logicalKey == LogicalKeyboardKey.goBack || event.logicalKey == LogicalKeyboardKey.goHome || event.logicalKey == LogicalKeyboardKey.allCandidates || event.logicalKey == LogicalKeyboardKey.cancel || event.logicalKey == LogicalKeyboardKey.browserBack || event.physicalKey == PhysicalKeyboardKey.escape || event.physicalKey == PhysicalKeyboardKey.exit || event.physicalKey == PhysicalKeyboardKey.browserBack || event.physicalKey == PhysicalKeyboardKey.close || event.physicalKey == PhysicalKeyboardKey.undo) { Future.delayed(0.ms, () { setState(() { isOpenFab = false; }); }); return true; } return false; }, child: /// finansServis?.animasyonluWidgetAc( mevcutWidget: (context, action) => Container( decoration: BoxDecoration( // color: isOpenFab ? Theme.of(context).extension()?.cardBackgroundColor : Colors.white, borderRadius: BorderRadius.circular(isOpenFab ? 5 : 35), ), child: FikoYTButton( text: FittedBox( clipBehavior: Clip.hardEdge, fit: BoxFit.scaleDown, child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ FikoYTButton( text: "🔖", tema: FikoYTButtonTheme( // backgroundColor: Colors.amberAccent, radius: 0, fontSize: 48, ), ), FikoYTButton( text: " Alt Kategori Ekle", tema: FikoYTButtonTheme( // backgroundColor: Colors.amberAccent, radius: 0, fontWeight: FontWeight.bold, ), ), FikoYTButton( text: "Yeni Alt Kategori Eklemeniz İçin \n Akçalıya Yönlendirir", tema: FikoYTButtonTheme( textAlign: TextAlign.center, radius: 0, fontWeight: FontWeight.w300, fontSize: 10, ), ), ], ), ), // onPressed: () { // dialogaKategoriEkleGoster(context); // }, ), ), acilacakWidget: (context, action) => SayfaKategoriEkle(animClose: action, kyt: null, ustKyt: widget.kyt.value.obs), onClosed: (p0) async { widget.kyt.value = await logicKategoriler?.getir(widget.kyt.value.id) ?? widget.kyt.value; widget.kyt.refresh(); logicKategoriler?.listeyiYenile(); }, ), ), ), ), onTapInside: (v) { setState(() { isOpenFab = true; }); // if (!isOpen) { // setState(() { // width = 200; // height = 200; // left = 60; // bottom = 60; // isOpen = !isOpen; // }); // } }, onTapOutside: (event) { setState(() { isOpenFab = false; }); }, ), ).animate(effects: [SlideEffect(begin: Offset(20, 0), delay: 50.ms, duration: 1000.ms)]), // onStretchTrigger: () async { // context.vRouter.to("/"); // }, headerWidget: Obx( () => HeaderWidget( ovalResimUrl: widget.kyt.value.simge ?? "🔖", baslik: widget.kyt.value.ismi ?? "İsimsiz Kategori", baslikTheme: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.secondaryTextColor, fontWeight: FontWeight.bold, fontSize: 16, ), altBaslik: widget.kyt.value.aciklama ?? "${widget.kyt.value.ismi != null ? '${widget.kyt.value.ismi} İsimli' : 'İsim Verilmemiş'} Kategorinizi Yönetin", altBaslikTheme: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.tertiaryTextColor, fontWeight: FontWeight.normal, fontSize: 12, ), ), ), headerBottomBar: Container( color: Theme.of(context).extension()?.cardBackgroundColor?.withAlpha(200), child: Row( children: [ FikoYTButton( text: "🗑", tema: Theme.of(context).extension()?.copyWith(edgePadding: EdgeInsets.all(5)), onPressed: () async { AwesomeDialog( context: context, dialogType: DialogType.question, animType: AnimType.scale, headerAnimationLoop: false, title: 'Silme Onayı', titleTextStyle: TextStyle(color: Theme.of(context).extension()?.infoTextColor, fontSize: 16), desc: '${widget.kyt.value.ismi ?? ""} Kategorisi Silinecek. Onaylıyormusunuz?', btnCancelOnPress: () { // context.vRouter.pop(); }, btnCancelColor: Colors.green, btnCancelText: "İptal", btnOkOnPress: () async { await logicKategoriler?.sil(kyt: widget.kyt.value); /// Başarılı toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.warning, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text("${widget.kyt.value.ismi ?? ""} Kategorisi Silindi."), alignment: Alignment.topRight, autoCloseDuration: const Duration(seconds: 4), borderRadius: BorderRadius.circular(4.0), boxShadow: lowModeShadow, showProgressBar: false, dragToClose: true, applyBlurEffect: true, ); // widget.animClose != null ? widget.animClose!() : null; Navigator.pop(context); }, btnOkColor: Colors.red, btnOkText: "Sil", ).show(); }, ), Spacer(), finansServis?.animasyonluWidgetAc( mevcutWidget: (context, action) => FikoYTButton( text: "🖋", tema: Theme.of(context).extension()?.copyWith(edgePadding: EdgeInsets.all(5)), onPressed: action, // () { // context.vRouter.to("/uye/hesaplar/hesap/${widget.hesapId}/duzenle"); // }, ), onClosed: (p0) { // widget.kyt.value = logicKategoriler?.byIdSync(widget.kyt.value.id) ?? widget.kyt.value; widget.kyt.refresh(); logicKategoriler?.guncelle.refresh(); setState(() {}); }, acilacakWidget: (context, action) => SayfaKategoriEkle(kyt: widget.kyt.value, animClose: action), ), ], ), ), /// golgeGoster: false, bodyColor: Colors.transparent, bodyMaxWidth: 400, sliverAltKisim: SizedBox.shrink(), body: [ /// Container( decoration: BoxDecoration( color: Theme.of(context).extension()?.cardBackgroundColor, borderRadius: BorderRadius.circular(0), border: Border.all(color: Colors.grey.shade400), ), padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5), margin: EdgeInsets.symmetric(vertical: 0, horizontal: 0), child: Row( children: [ Obx( () => FikoYTButton( text: "Alt Kategoriler (${widget.kyt.value.altKategoriler.countSync() > 0 ? ('${widget.kyt.value.altKategoriler.countSync()} Adet') : 'Yok'})", tema: FikoYTButtonTheme(fontSize: 12), ), ), Spacer(), finansServis?.animasyonluWidgetAc( routeSettings: RouteSettings(name: "/uye/akcali/kategoriler", arguments: null), mevcutWidget: (context, action) { // girisAction = action; return FikoYTButton( text: "+", tema: FikoYTButtonTheme( fontSize: 18, fontWeight: FontWeight.bold, edgePadding: EdgeInsets.symmetric(horizontal: 3, vertical: 3), ), ); }, acilacakWidget: (context, action) { return SayfaKategoriEkle(ustKyt: widget.kyt, animClose: action); }, onClosed: (p0) { setState(() { widget.kyt.refresh(); }); }, ), ], ), ), /// Obx(() { widget.kyt.value; logicKategoriler?.guncelle.value; return AnimatedSwitcher( duration: const Duration(milliseconds: 500), layoutBuilder: (Widget? currentChild, List previousChildren) { return Stack( alignment: Alignment.topCenter, children: [...previousChildren, if (currentChild != null) currentChild], ); }, transitionBuilder: (Widget child, Animation animation) { return FadeTransition( opacity: animation, child: SizeTransition(sizeFactor: animation, axisAlignment: 1.0, child: Center(child: child)), ); }, // visible: logic.aktifHareket.value != null ? logic.aktifHareket.value!.altKartlar.isEmpty : false, child: (widget.kyt.value.altKategoriler.countSync()) <= 0 ? Container( // width: double.infinity, padding: const EdgeInsets.only(bottom: 20, top: 20, left: 5, right: 5), margin: EdgeInsets.all(10), decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), color: Colors.white, border: Border.all(color: Colors.grey.shade400), // boxShadow: [ // BoxShadow(color: Colors.teal.withOpacity(0.15), spreadRadius: -15.0, blurRadius: 12.0), // const BoxShadow(color: Colors.transparent, spreadRadius: -5.0, blurRadius: 12.0), // ], ), child: Column( children: [ const Row( mainAxisAlignment: MainAxisAlignment.center, children: [Text("🔖", style: TextStyle(fontSize: 36))], ), FikoYTButton( text: "Alt Kategori Yok", tema: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.errorTextColor, textStrokeColor: Colors.white, fontSize: 16, ), ), Center( child: finansServis?.animasyonluWidgetAc( mevcutWidget: (context, action) => Container( decoration: BoxDecoration( // color: isOpenFab ? Theme.of(context).extension()?.cardBackgroundColor : Colors.white, borderRadius: BorderRadius.circular(isOpenFab ? 5 : 35), ), child: FikoYTButton( text: 'Yeni Alt Kategori', tema: Theme.of(context).extension()?.copyWith( textAlign: TextAlign.center, textStrokeColor: Colors.transparent, textColor: Theme.of(context).extension()?.infoTextColor, // textShadow: [], edgePadding: EdgeInsets.symmetric(horizontal: 15), ), ), ), acilacakWidget: (context, action) => SayfaKategoriEkle(animClose: action, kyt: null, ustKyt: widget.kyt.value.obs), ), ), ], ), ) : Builder( builder: (context) { // widget.kyt.value.altKategoriler.loadSync(); List snapshot = widget.kyt.value.altKategoriler.toList(); return Column( children: [ snapshot.isNotEmpty ? ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: snapshot.length, itemBuilder: (context, index) { return KategoriItem(kyt: snapshot[index], animClose: widget.animClose); }, ) : SizedBox.shrink(), /** */ ], ); }, ), ); }), ], ); } }