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/hareketler/hareket-ekle/_logic_hareket_ekle.dart'; import 'package:fikoyt_akcali_v1/apps/finans/uye/kategoriler/kategoriler.dart'; import 'package:fikoyt_ui/fikoyt_ui.dart'; import 'package:fikoyt_ui/ui/fikoyt_card.dart'; import 'package:fikoyt_ui/ui/yazi_kutulari/yazi_kutulari.dart'; import 'package:flutter/material.dart'; class KategoriSecDialog extends StatefulWidget { KategoriSecDialog({super.key}); // Rx? ustKategori; @override State createState() => _KategoriSecDialogState(); } class _KategoriSecDialogState extends State { final KategorilerService kategorilerServis = KategorilerService(); final FinansServis? finansServis = FikoYTCoreService.servisler.getServis(); final HareketEkleService logic = Get.put(HareketEkleService()); final ScrollController _scrollController = ScrollController(); @override void dispose() { _scrollController.dispose(); kategorilerServis.dispose(); super.dispose(); } void scrollToBottomDelayed() { Future.delayed(const Duration(milliseconds: 300), () { if (_scrollController.hasClients) { _scrollController.animateTo( _scrollController.position.maxScrollExtent + 100, duration: const Duration(milliseconds: 400), curve: Curves.easeOut, ); } }); } @override Widget build(BuildContext context) { return FikoYTCard( key: ValueKey("KategoriListesiDialog"), theme: (Theme.of(context).extension() ?? FikoYTCardTheme()).copyWith( boxConstraints: BoxConstraints(maxWidth: 300), backgroundColor: Theme.of(context).extension()?.backgroundColor, padding: EdgeInsets.zero, ), children: [ Center(child: Text('💸', style: TextStyle(fontSize: 54))), Center( child: FikoYTButton( text: 'Kategori Seç', tema: Theme.of(context).extension()?.copyWith( textAlign: TextAlign.center, textStrokeColor: Colors.transparent, textColor: Theme.of(context).extension()?.infoTextColor, // textShadow: Theme.of(context).extension()?.textShadow, ), ), ), /** Seçilen Kategoriler */ 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: 5, vertical: 5), margin: EdgeInsets.symmetric(vertical: 0, horizontal: 0), child: Row( children: [ FikoYTButton(text: "Seçilen Kategoriler", tema: FikoYTButtonTheme(fontSize: 12)), Spacer(), Obx( () => AnimatedFikoYTButton1( text: logic.kategoriler.isNotEmpty ? "${logic.kategoriler.length} Adet" : "Yok", tema: FikoYTButtonTheme(fontSize: 12), ), ), ], ), ), /// Mini Liste Obx( () => 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), ), ); }, child: logic.kategoriler.isNotEmpty ? Padding( padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5), child: Wrap( spacing: 2, runSpacing: 2, children: (logic.kategoriler.toList()) .asMap() .entries .map((entry) { int index = entry.key; return FikoYTButton( text: "${logic.kategoriler[index].simge} ${logic.kategoriler[index].ismi}", tema: FikoYTButtonTheme( fontSize: 12, backgroundColor: Colors.white, fontWeight: FontWeight.w200, edgePadding: EdgeInsets.all(2), borderColor: Colors.blue, ), onPressed: () { logic.kategoriler.removeWhere((element) => element.id == logic.kategoriler[index].id); logic.kategoriler.refresh(); }, ); }) .toList() .cast(), ), ) : Container( padding: const EdgeInsets.only(bottom: 10, top: 10, left: 5, right: 5), margin: EdgeInsets.all(5), decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), color: Theme.of(context).extension()?.cardBackgroundColor, border: Border.all(color: Colors.grey.shade400), ), child: Column( children: [ const Row( mainAxisAlignment: MainAxisAlignment.center, children: [Text("💸", style: TextStyle(fontSize: 32))], ), FikoYTButton( text: "Seçilen Kategori Yok", tema: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.errorTextColor, textStrokeColor: Colors.white, fontSize: 12, ), ), ], ), ), ), ), ], ), Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, spacing: 5, children: [ Obx( () => FikoYaziKutusu( baslik: "Arama Yap", simgeSol: const Text("✏️", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: kategorilerServis.aramaMetni, anlikDegistiOlayi: true, degisti: (value) async { // kategorilerServis.listeyiSifirla(); kategorilerServis.aramaYap(value); }, ), ), Divider(height: 4), Container( decoration: BoxDecoration( color: Theme.of(context).extension()?.cardBackgroundColor, borderRadius: BorderRadius.circular(0), border: Border.all(color: Colors.grey.shade400), ), padding: EdgeInsets.symmetric(horizontal: 5, vertical: 5), margin: EdgeInsets.symmetric(vertical: 0, horizontal: 0), child: Row( children: [ AnimatedFikoYTButton1( text: kategorilerServis.ustKategori.value != null ? "<" : " ", tema: FikoYTButtonTheme(fontSize: 14, edgePadding: EdgeInsets.symmetric(horizontal: 5, vertical: 2)), onPressed: () { setState(() { kategorilerServis.ustKategori.value = kategorilerServis.ustKategori.value?.ustKategori.value; kategorilerServis.listeyiYenile(); }); }, ), AnimatedFikoYTButton1( text: kategorilerServis.ustKategori.value != null ? "${kategorilerServis.ustKategori.value?.simge}${kategorilerServis.ustKategori.value?.ismi} Alt Kategorileri" : "Kategori Listesi", tema: FikoYTButtonTheme(fontSize: 12), ), Obx( () => AnimatedFikoYTButton1( text: "(${kategorilerServis.veriSayisi < 1 ? 'Yok' : (kategorilerServis.veriSayisi.toString() + ' Adet')})", 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 SayfaKategoriler(); }, onClosed: (p0) { setState(() { logic.kategoriler.refresh(); logic.kyt.refresh(); }); }, ), ], ), ), /// Obx( () => 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: kategorilerServis.veriSayisi <= 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: Theme.of(context).extension()?.cardBackgroundColor, 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 Bulunamadı", tema: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.errorTextColor, textStrokeColor: Colors.white, fontSize: 16, ), ), /** */ ], ), ) : ConstrainedBox( constraints: BoxConstraints(maxHeight: 300), child: ListView.builder( key: ValueKey(kategorilerServis.veriSayisi), controller: _scrollController, physics: const BouncingScrollPhysics(), shrinkWrap: true, itemCount: kategorilerServis.liste.length, itemBuilder: (context, index) { return KategorilerDialogItem( ktgr: kategorilerServis.liste[index], onTap: () { setState(() { if (kategorilerServis.liste[index].altKategoriler.countSync() > 0) { kategorilerServis.aramaYap(""); kategorilerServis.ustKategori.value = kategorilerServis.liste[index]; } else { bool varmi = false; for (var item in logic.kategoriler) { if (item.id == kategorilerServis.liste[index].id) { varmi = true; break; } } if (varmi) { logic.kategoriler.removeWhere( (element) => element.id == kategorilerServis.liste[index].id, ); } else { logic.kategoriler.add(kategorilerServis.liste[index]); } logic.kategoriler.refresh(); } // widget.ustKategori = data[index].obs; }); }, ); }, ), ), ), ), Obx( () => Row( children: [ Visibility( visible: kategorilerServis.dahaAzGoster, child: Column( children: [ FikoYTButton( text: "Daha Az", tema: FikoYTButtonTheme( textColor: Theme.of(context).extension()?.infoTextColor, fontSize: 14, ), onPressed: () async { await kategorilerServis.dahaAz(); }, ), ], ), ), Spacer(), // Visibility( // visible: (hesaplarServis?.limit.value ?? 0) > (hesaplarServis?.sayi.value ?? 3), // child: Visibility( visible: kategorilerServis.dahaSifirlaGoster, child: Column( children: [ FikoYTButton( text: "Sıfırla", tema: FikoYTButtonTheme( textColor: Theme.of(context).extension()?.infoTextColor, fontSize: 14, ), onPressed: () { kategorilerServis.dahaSifirla(); }, ), ], ), ), // ), // if (((hesaplarServis?.limit.value ?? 0) < // (finansServis?.aktifKullanici.value?.hesaplar.filter().countSync() ?? 0))) if (kategorilerServis.dahaFazlaGoster) Spacer(), Visibility( visible: kategorilerServis.dahaFazlaGoster, child: Column( children: [ FikoYTButton( text: "Daha Fazla", tema: FikoYTButtonTheme( textColor: Theme.of(context).extension()?.infoTextColor, fontSize: 14, ), onPressed: () async { await kategorilerServis.dahaFazla(); scrollToBottomDelayed(); }, ), ], ), ), ], ), ), /// Padding( padding: const EdgeInsets.all(8.0), child: Row( children: [ Spacer(), FikoYTButton( text: "❌ Kapat", tema: FikoYTButtonTheme( // textColor: Colors.white, backgroundColor: Colors.transparent, // fontWeight: FontWeight.w700, edgePadding: EdgeInsets.all(3), borderColor: Colors.red, elevation: 3, fontSize: 12, ), onPressed: () async { context.vRouter.pop(); }, ), ], ), ), ], ), ), ], ); } } class KategorilerDialogItem extends StatelessWidget { KategorilerDialogItem({super.key, required this.ktgr, this.onTap}); final Kategori ktgr; final Function()? onTap; final HareketEkleService logic = Get.put(HareketEkleService()); @override Widget build(BuildContext context) { return FikoYTButton( onPressed: onTap, text: Container( margin: EdgeInsets.symmetric(vertical: 2, horizontal: 10), decoration: BoxDecoration( borderRadius: BorderRadius.circular(5), color: Theme.of(context).extension()?.cardBackgroundColor, border: Border.all(color: Colors.grey.shade400), ), padding: EdgeInsets.all(3), child: Row( children: [ Container( decoration: BoxDecoration(borderRadius: BorderRadius.circular(5), color: ktgr.rengi), child: FikoYTButton(text: "${ktgr.simge}", tema: FikoYTButtonTheme(fontSize: 32)), ), const SizedBox(width: 2), // Boşluk eklemek için Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ FikoYTButton(text: "${ktgr.ismi}"), FikoYTButton( text: ktgr.altKategoriler.countSync() > 0 ? ('${ktgr.altKategoriler.countSync()} adet alt kategorisi var') : 'Alt kategorisi yok', tema: FikoYTButtonTheme(fontWeight: FontWeight.w200, fontSize: 12), ), Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Obx(() { // ignore: invalid_use_of_protected_member logic.kategoriler.value; return Builder( builder: (context) { var secili = logic.kategoriler.where((item) => item.id == ktgr.id).isEmpty; return FikoYTButton( text: secili ? "Seç" : "Seçimi Kaldır", tema: FikoYTButtonTheme( fontWeight: FontWeight.w200, fontSize: 10, backgroundColor: secili ? Colors.blue : Colors.red, textColor: Colors.white, edgePadding: EdgeInsets.all(2), ), onPressed: () { bool varmi = false; for (var item in logic.kategoriler) { if (item.id == ktgr.id) { varmi = true; break; } } if (varmi) { logic.kategoriler.removeWhere((element) => element.id == ktgr.id); } else { logic.kategoriler.add(ktgr); } logic.kategoriler.refresh(); }, ); }, ); }), ], ), ], ), ), ], ), ), ); // Container( // padding: EdgeInsets.all(3), // child: ListTileTheme( // contentPadding: EdgeInsets.zero, // dense: true, // horizontalTitleGap: 0, // minVerticalPadding: 0, // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)), // child: ListTile( // leading: FikoYTButton(text: "${hsp.simgesi}"), // title: FikoYTButton(text: "${hsp.ismi} ${hsp.paraBirimi.value?.sembol}"), // trailing: FikoYTButton(text: "${hsp.bakiye?.toParaBirimi()}"), // tileColor: Theme.of(context).extension()?.cardBackgroundColor, // isThreeLine: false, // onTap: () { // Navigator.of(context).pop(hsp); // }, // subtitle: FikoYTButton( // text: hsp.aciklama ?? 'Açıklama Yok', // tema: FikoYTButtonTheme(fontWeight: FontWeight.w200, fontSize: 12), // ), // ), // ), // ); } }