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'; import 'package:isar/isar.dart'; class SayfaKategoriler extends StatefulWidget { SayfaKategoriler({super.key, this.animClose}); void Function({Never returnValue})? animClose; @override State createState() => _SayfaKategorilerState(); } class _SayfaKategorilerState extends State { FinansServis? finansServis = FikoYTCoreService.servisler.getServis(); KategorilerService? logic; 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(); logic = Get.put(KategorilerService()); } @override void dispose() { // Get.delete(); super.dispose(); } @override Widget build(BuildContext context) { return FikoYTSliverApp( leading: UygulamaBaslikSol(), title: UygulamaBaslikOrta(altBaslik: "Kategoriler"), actions: [UygulamaBaslikSag()], drawer: finansServis?.solMenu.value, backgroundColor: Theme.of(context).extension()?.backgroundColor, appBarColor: Theme.of(context).extension()?.appBarColor?.withAlpha(230), headerExpandedHeight: 230, // stretchMaxHeight: 100, fullyStretchable: true, centerTitle: true, alwaysShowLeadingAndAction: true, alwaysShowTitle: true, curvedBodyRadius: 0, // onStretchTrigger: () async { // context.vRouter.to("/"); // }, 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.blue, 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.white, // 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( ozelId: "Ana-Fab-Hesap-Gelir-Ekle", routeSettings: RouteSettings(name: "/uye/hareketler/ekle"), 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: "Kategori Ekle", tema: FikoYTButtonTheme( // backgroundColor: Colors.amberAccent, radius: 0, fontWeight: FontWeight.bold, ), ), FikoYTButton( text: "Yeni 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), ), ), ), ), onTapInside: (v) { setState(() { isOpenFab = true; }); // if (!isOpen) { // setState(() { // width = 200; // height = 200; // left = 60; // bottom = 60; // isOpen = !isOpen; // }); // } }, onTapOutside: (event) { setState(() { isOpenFab = false; }); }, ), ), /// headerWidget: HeaderWidget( ovalResimUrl: "🔖", baslik: "Kategoriler", baslikTheme: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.secondaryTextColor, fontWeight: FontWeight.bold, fontSize: 16, ), altBaslik: "Sisteminize Tanımlanmış Kategoriler", altBaslikTheme: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.tertiaryTextColor, fontWeight: FontWeight.normal, fontSize: 12, ), ), /// sliverAltKisimGoster: false, /// golgeGoster: false, bodyColor: Colors.transparent, body: [ /// Column( children: [ /** */ 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: [ FikoYTButton(text: "Kategoriler", 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)); }, acilacakWidget: (context, action) => SayfaKategoriEkle(animClose: action, kyt: null), ), FikoYTButton( text: "🧾", tema: FikoYTButtonTheme(fontSize: 18), onPressed: () { Kategori.fromJson({ "kategori": "Gelir", "simge": "💰", "kod": "income", "rengi": 16777215, "altKategoriler": [ { "kategori": "Maaş", "simge": "💸", "kod": "salary", "rengi": 15790320 }, { "kategori": "Ek Gelir", "simge": "📈", "kod": "extra_income", "rengi": 6710886 }, { "kategori": "Yatırım Geliri", "simge": "📊", "kod": "investment_income", "rengi": 16777215 }, { "kategori": "Bağışlar", "simge": "❤️", "kod": "donations", "rengi": 15790320 }, { "kategori": "Hediye", "simge": "🎁", "kod": "gift", "rengi": 6710886 } ] }).save(isar: finansServis!.isar!, sahibi: finansServis?.aktifKullanici.value, ustKategori: null); }, ), ], ), ), /// Obx(() { logic?.kayit.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: (finansServis?.isar?.kategoris.where().countSync() ?? 0) <= 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: "Kategori Yok", tema: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.errorTextColor, textStrokeColor: Colors.white, fontSize: 16, ), ), Center( key: ValueKey("asdasdadqwaasfdasdsa"), child: finansServis?.animasyonluWidgetAc( mevcutWidget: (p0, p1) => FikoYTButton( text: 'Yeni 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), ), ), ], ), ) : Builder( builder: (context) { List snapshot = logic?.listeAlSync(0, 1000) ?? []; return Column( children: [ snapshot.isNotEmpty ? ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: logic?.listeAlSync(0, 99999999).length ?? 0, itemBuilder: (context, index) { return KategoriItem(kyt: snapshot[index], animClose: widget.animClose); }, ) : SizedBox.shrink(), /** */ ], ); }, ), ); }), ], ), ], ); } }