import 'package:animations/animations.dart'; 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/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/scheduler.dart'; import 'package:isar/isar.dart'; class SayfaParaBirimleriService extends GetxService { Rx kayit = Rx(ParaBirimi()); Rx kayitEkleGoster = Rx(false); FinansServis? finansServis = FikoYTCoreService.servisler.getServis(); Isar? isar = FikoYTCoreService.servisler.getServis()?.isar; kayitKontrol() { kayit.value?.ismi != ""; } kaydet({required ParaBirimi kyt}) { isar?.writeTxn(() async { if (kyt.aciklama == "") { kyt.aciklama = null; } kyt.sahibi.value = finansServis?.aktifKullanici.value; await isar?.paraBirimis.put(kyt); await kyt.sahibi.save(); kayit.value = ParaBirimi(); kayitEkleGoster.value = false; kayitEkleGoster.refresh(); kayit.refresh(); }); } sil({required ParaBirimi kyt}) { isar?.writeTxn(() async { isar?.paraBirimis.delete(kyt.id); kayit.value = ParaBirimi(); kayitEkleGoster.value = false; kayitEkleGoster.refresh(); kayit.refresh(); }); } Future> listeAl(int page, int limit) async { return await isar?.paraBirimis .where() .filter() .sahibi((q) => q.idEqualTo(finansServis?.aktifKullanici.value?.id ?? -1)) .sortByIsmi() .offset(page * limit) .limit(limit) .findAll() ?? []; } List listeAlSync(int page, int limit) { return isar?.paraBirimis .where() .filter() .sahibi((q) => q.idEqualTo(finansServis?.aktifKullanici.value?.id ?? -1)) .offset(page * limit) .limit(limit) .findAllSync() ?? []; } } class SayfaParaBirimleri extends StatefulWidget { const SayfaParaBirimleri({super.key}); @override State createState() => _SayfaParaBirimleriState(); } class _SayfaParaBirimleriState extends State { FinansServis? finansServis; SayfaParaBirimleriService? logic; @override void initState() { super.initState(); finansServis = FikoYTCoreService.servisler.getServis(); logic = Get.put(SayfaParaBirimleriService()); SchedulerBinding.instance.addPostFrameCallback((_) { finansServis?.altBaslik.value = "Para Birimleri"; }); } @override void dispose() { // Get.delete(); super.dispose(); } @override Widget build(BuildContext context) { return FikoYTSliverApp( leading: UygulamaBaslikSol(), title: UygulamaBaslikOrta(), actions: [UygulamaBaslikSag()], drawer: finansServis?.solMenuAl(context), 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("/"); // }, /// 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, ), ), /// golgeGoster: false, bodyColor: Colors.transparent, body: [ SizedBox(height: 15), /** */ FikoYTCard( theme: (Theme.of(context).extension() ?? FikoYTCardTheme()).copyWith( boxConstraints: BoxConstraints(maxWidth: 300), ), 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: [ Row( children: [ FikoYTButton(text: "Para Birimleri", tema: FikoYTButtonTheme(fontSize: 12)), Spacer(), FikoYTButton(text: "➜", onPressed: () {}), ], ), 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: Colors.transparent, 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 OpenContainer( closedColor: Colors.transparent, closedElevation: 0, middleColor: Colors.transparent, openElevation: 0, transitionDuration: Duration(milliseconds: 1000), transitionType: ContainerTransitionType.fade, tappable: true,openColor: Colors.transparent,useRootNavigator: false,clipBehavior: Clip.hardEdge, closedBuilder: (context, action) => Container( color: Colors.transparent, 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: () {}, subtitle: FikoYTButton( text: snapshot[index].aciklama ?? 'Açıklama Yok', tema: FikoYTButtonTheme(fontWeight: FontWeight.w200, fontSize: 12), ), ), ), ), openBuilder: (context, action) => Center( child: Material( color: Colors.transparent, child: SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.min, // Küçük diyalog olacak children: [formParaBirimiEkle(context, kyt: snapshot[index].obs)], ), // İçeriği buraya koyuyoruz ), ), ), ); } Future dialogParaBirimiEkleGoster(BuildContext context, {Rx? kyt}) { return showGeneralDialog( context: context, barrierDismissible: true, barrierColor: Colors.transparent, barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, transitionDuration: const Duration(milliseconds: 400), 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; }, ), 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(); }, ), ], ), ], ), ), ), ], ); } }