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/para_birimleri_service.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:fikoyt_ui/ui/yazi_kutulari/yazi_kutulari.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:isar/isar.dart'; class SayfaParaBirimleri extends StatefulWidget { const SayfaParaBirimleri({super.key}); @override State createState() => _SayfaParaBirimleriState(); } class _SayfaParaBirimleriState extends State { FinansServis? finansServis = FikoYTCoreService.servisler.getServis(); ParaBirimleriService? 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(ParaBirimleriService()); } @override void dispose() { // Get.delete(); super.dispose(); } @override Widget build(BuildContext context) { return FikoYTSliverApp( leading: UygulamaBaslikSol(), title: UygulamaBaslikOrta(altBaslik: "Para Birimleri"), 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: /// 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: "Yeni Para Birimi", tema: FikoYTButtonTheme( // backgroundColor: Colors.amberAccent, radius: 0, fontWeight: FontWeight.bold, ), ), FikoYTButton( text: "Sisteminize Para Birimi \n Eklemeniz İçin Yönlendirir", tema: FikoYTButtonTheme( textAlign: TextAlign.center, radius: 0, fontWeight: FontWeight.w300, fontSize: 10, ), ), ], ), ), onPressed: () { dialogParaBirimiEkleGoster(context); }, ), ), ), ), ), onTapInside: (v) { setState(() { isOpenFab = true; }); // if (!isOpen) { // setState(() { // width = 200; // height = 200; // left = 60; // bottom = 60; // isOpen = !isOpen; // }); // } }, onTapOutside: (event) { setState(() { isOpenFab = false; }); }, ), ), /// headerWidget: Obx( () => HeaderWidget( ovalResimUrl: finansServis?.aktifKullanici.value?.profilResmiUrl ?? "🏠", baslik: finansServis?.aktifKullanici.value?.ismi, baslikTheme: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.secondaryTextColor, fontWeight: FontWeight.bold, fontSize: 16, ), altBaslik: "Sisteminizdeki Para Birimleri", altBaslikTheme: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.tertiaryTextColor, fontWeight: FontWeight.normal, fontSize: 12, ), ovalResimTiklandi: finansServis?.profilResmiDegistir, ovalResimCiftTiklandi: finansServis?.profilResmiSil, ), ), /// golgeGoster: false, bodyColor: Colors.transparent, sliverAltKisimGoster: false, body: [ SizedBox(height: 15), /** */ FikoYTCard( theme: (Theme.of(context).extension() ?? FikoYTCardTheme()).copyWith( boxConstraints: BoxConstraints(maxWidth: 350), ), children: [ Center( child: FikoYTButton( text: 'Ana Para Birimi', tema: Theme.of(context).extension()?.copyWith( textAlign: TextAlign.center, textStrokeColor: Colors.transparent, textColor: Theme.of(context).extension()?.secondaryTextColor, // textShadow: Theme.of(context).extension()?.textShadow, ), ), ), Divider(height: 4), Center( child: Text( '₺ TRY ', style: TextStyle(fontSize: 36, color: Theme.of(context).extension()?.secondaryTextColor), ), ), // SizedBox(height: 1400), ], ), ///$ Container( margin: EdgeInsets.symmetric(vertical: 10), constraints: BoxConstraints(maxWidth: 300), child: 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: "Para Birimleri", tema: FikoYTButtonTheme(fontSize: 12)), Spacer(), FikoYTButton( text: "+", tema: FikoYTButtonTheme(fontSize: 18), onPressed: () { dialogParaBirimiEkleGoster(context); }, ), ], ), ), // Row( // children: [ // FikoYTButton(text: "Para Birimleri", tema: FikoYTButtonTheme(fontSize: 12)), // Spacer(), // FikoYTButton( // text: "+", // tema: FikoYTButtonTheme( // // backgroundColor: Colors.amberAccent, // radius: 0, // fontSize: 18, // ), // onPressed: () { // dialogParaBirimiEkleGoster(context); // }, // ), // ], // ), Divider(height: 4), 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?.paraBirimis.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: 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: "Başka Para Birimi Yok", tema: Theme.of(context).extension()?.copyWith( textColor: Theme.of(context).extension()?.errorTextColor, textStrokeColor: Colors.white, fontSize: 16, ), ), // /** */ paraBirimiEkleBolumu(context), ], ), ) : Builder( builder: (context) { List snapshot = finansServis?.isar?.paraBirimis.where().findAllSync() ?? []; return Column( children: [ snapshot.isNotEmpty ? ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: finansServis?.isar?.paraBirimis.where().countSync() ?? 0, itemBuilder: (context, index) { return paraBirimiItem(snapshot, index, context); // FikoYTButton( // text: // "${snapshot[index].kod} ${snapshot[index].ismi} ${snapshot[index].sembol} -> ${snapshot[index].oran}", // ); }, ) : SizedBox.shrink(), /** */ // paraBirimiEkleBolumu(context), ], ); }, ), ); }), ], ), ), ], ); } Widget paraBirimiItem(List snapshot, int index, BuildContext context) { return 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: "${snapshot[index].sembol}"), title: FikoYTButton(text: "${snapshot[index].ismi} ${snapshot[index].kod}"), trailing: FikoYTButton(text: "${snapshot[index].oran}"), tileColor: Theme.of(context).extension()?.cardBackgroundColor, isThreeLine: false, onTap: () { dialogParaBirimiEkleGoster(context, kyt: snapshot[index].obs); }, subtitle: FikoYTButton( text: snapshot[index].aciklama ?? 'Açıklama Yok', tema: FikoYTButtonTheme(fontWeight: FontWeight.w200, fontSize: 12), ), ), ), ); } Future dialogParaBirimiEkleGoster(BuildContext context, {Rx? kyt}) { return showGeneralDialog( context: context, barrierDismissible: true, // barrierColor: Colors.transparent, barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, transitionDuration: Duration(milliseconds: ((finansServis?.openContainerDuration.inMilliseconds ?? 0)).toInt()), pageBuilder: (context, animation, secondaryAnimation) { return Center( child: Material( color: Colors.transparent, child: SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.min, // Küçük diyalog olacak children: [formParaBirimiEkle(context, kyt: kyt)], ), // İçeriği buraya koyuyoruz ), ), ); }, transitionBuilder: (context, animation, secondaryAnimation, child) { return ScaleTransition( scale: Tween(begin: 0.7, end: 1.0).animate(CurvedAnimation(parent: animation, curve: Curves.easeOutBack)), child: FadeTransition(opacity: animation, child: child), ); }, ); // return showDialog( // context: context, // builder: // (context) => // AlertDialog(content: formParaBirimiEkle(context, kyt: kyt), backgroundColor: Colors.transparent, scrollable: true), // ); } Obx paraBirimiEkleBolumu(BuildContext context, {Rx? kyt}) { return 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: logic!.kayitEkleGoster.value ? formParaBirimiEkle(context, kyt: kyt) : Center( key: ValueKey("asdasdadqwasa"), child: FikoYTButton( text: 'Yeni Para Birimi', tema: Theme.of(context).extension()?.copyWith( textAlign: TextAlign.center, textStrokeColor: Colors.transparent, textColor: Theme.of(context).extension()?.infoTextColor, // textShadow: [], edgePadding: EdgeInsets.symmetric(horizontal: 15), ), onPressed: () { dialogParaBirimiEkleGoster(context); }, ), ), ), ); } FikoYTCard formParaBirimiEkle(BuildContext context, {Rx? kyt}) { Rx kayit; if (kyt?.value == null) { kayit = Rx(ParaBirimi()); } else { kayit = Rx(kyt!.value!); } return FikoYTCard( key: ValueKey("ParaBirimiEkleDialog"), theme: (Theme.of(context).extension() ?? FikoYTCardTheme()).copyWith( boxConstraints: BoxConstraints(maxWidth: 300), ), children: [ Center(child: Text('💸', style: TextStyle(fontSize: 54))), Center( child: FikoYTButton( text: kyt?.value?.id == null ? 'Yeni Para Birimi' : 'Para Birimi Güncelle', tema: Theme.of(context).extension()?.copyWith( textAlign: TextAlign.center, textStrokeColor: Colors.transparent, textColor: Theme.of(context).extension()?.infoTextColor, // textShadow: Theme.of(context).extension()?.textShadow, ), ), ), Divider(height: 4), Obx( () => Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, spacing: 5, children: [ FikoYaziKutusu( baslik: "Para İsmi", simgeSol: const Text("✏️", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: kayit.value.ismi, degisti: (value) { kayit.value.ismi = value; }, ), FikoYaziKutusu( baslik: "Kod", simgeSol: const Text("🏷️", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: kayit.value.kod, degisti: (value) { kayit.value.kod = value; }, ), FikoYaziKutusu( baslik: "Sembol", simgeSol: const Text("⭐", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: kayit.value.sembol, degisti: (value) { kayit.value.sembol = value; }, ), FikoYaziKutusu( baslik: "Oran", simgeSol: const Text("💯", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: kayit.value.oran.toString(), degisti: (value) { kayit.value.oran = double.tryParse(value) ?? 1; }, ), FikoYaziKutusu( baslik: "Ters Oran", simgeSol: const Text("🔁", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: kayit.value.tersOran.toString(), degisti: (value) { kayit.value.tersOran = double.tryParse(value) ?? 1; }, ), FikoYaziKutusu( baslik: "Küsürat", simgeSol: const Text("🧶", style: TextStyle(fontSize: 14)), yaziBoyutu: 12.0, radius: 5.0, degeri: kayit.value.kusurat.toString(), degisti: (value) { kayit.value.kusurat = int.tryParse(value) ?? 2; }, ), FikoAciklamaKutusu( baslik: "Açıklama", yaziBoyutu: 12.0, radius: 5.0, degeri: kayit.value.aciklama, degisti: (value) { kayit.value.aciklama = value; }, ), Row( children: [ 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 { logic?.kayitEkleGoster.value = false; logic?.kayitEkleGoster.refresh(); context.vRouter.pop(); }, ), Spacer(), if (kyt?.value != null) FikoYTIconButton( text: "Sil", icon: Icons.delete, tema: FikoYTButtonTheme( // textColor: Colors.white, backgroundColor: Colors.transparent, // fontWeight: FontWeight.w700, edgePadding: EdgeInsets.all(3), borderColor: Colors.blueAccent, elevation: 3, fontSize: 12, ), 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: '${kyt!.value?.ismi ?? ""} Para Birimi Silinecek. Onaylıyormusunuz?', btnCancelOnPress: () { // context.vRouter.pop(); }, btnCancelColor: Colors.green, btnCancelText: "İptal", btnOkOnPress: () { logic?.sil(kyt: kyt.value!); kayit.refresh(); /// Başarılı toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.warning, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text("Para Birimi Silindi."), alignment: Alignment.topRight, autoCloseDuration: const Duration(seconds: 4), borderRadius: BorderRadius.circular(4.0), // boxShadow: lowModeShadow, showProgressBar: false, dragToClose: true, applyBlurEffect: true, ); context.vRouter.pop(); }, btnOkColor: Colors.red, btnOkText: "Sil", ).show(); }, ), FikoYTIconButton( text: (kyt?.value != null) ? "Güncelle" : "Ekle", icon: (kyt?.value != null) ? Icons.update : Icons.add, tema: FikoYTButtonTheme( // textColor: Colors.white, backgroundColor: Colors.transparent, // fontWeight: FontWeight.w700, edgePadding: EdgeInsets.all(3), borderColor: Colors.blueAccent, elevation: 3, fontSize: 12, ), onPressed: () async { if (kayit.value.bosMu) { /// Boş toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.error, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text("Tüm Boş Alanları Doldurun."), alignment: Alignment.topRight, autoCloseDuration: const Duration(seconds: 4), borderRadius: BorderRadius.circular(4.0), // boxShadow: lowModeShadow, showProgressBar: false, dragToClose: true, applyBlurEffect: true, ); return; } logic?.kaydet(kyt: kayit.value); /// Başarılı toastification.show( context: FikoYTCoreService.navigatorKey.currentContext, type: ToastificationType.success, style: ToastificationStyle.fillColored, // title: Text("FikoYT Sistem"), description: Text("Para Birimi Tanımlandı."), alignment: Alignment.topRight, autoCloseDuration: const Duration(seconds: 4), borderRadius: BorderRadius.circular(4.0), // boxShadow: lowModeShadow, showProgressBar: false, dragToClose: true, applyBlurEffect: true, ); context.vRouter.pop(); }, ), ], ), ], ), ), ), ], ); } }