import 'dart:convert'; import 'dart:io'; import 'package:fikoyt_finans/apps/mesaici/model/ayarlar/model_ayarlar.dart'; import 'package:fikoyt_finans/apps/mesaici/pages/ayarlar/maas_parametreleri/ek_odeme_ekle.dart'; import 'package:fikoyt_finans/core/Extensions/fiko_double_ext.dart'; import 'package:fikoyt_finans/core/fikoyt.service.dart'; import 'package:fikoyt_finans/core/interface/fiko_dialog_ayarlari.dart'; import 'package:fikoyt_finans/core/widgets/fiko_ui/fiko_button/fiko_button.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:get/get.dart'; import '../../model/calisma_kayit/calisma_kayit.dart'; class EkOdemelerWidget extends StatelessWidget { EkOdemelerWidget({super.key, required this.kayit}); final Rx? kayit; // FikoYTMesaiciService FikoYTService.servisMesaici = Get.put(FikoYTMesaiciService()); FikoYTService servisFikoYT = FikoYTService(); final RxBool showToolbar = false.obs; @override Widget build(BuildContext context) { return Column( children: [ /** Ek Ödemeler */ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ FikoButton1( text: "🗑️", onPressed: () async { FikoYTService.dialogGoster( context, const Text("Aktif Karttaki Tüm Ek Ödemeler Silinecek.Bu İşlem Geri Alınamaz. Onaylıyormusunuz?"), FikoDialogAyarlari(baslik: "Onay", baslikSimge: "❔", altButonlar: [ FikoButton1( textColor: Colors.red, textStrokeColor: Colors.transparent, text: "✔️ Onaylıyorum", onPressed: () { kayit?.value?.ekOdemeler = []; FikoYTService.servisMesaici.aktifCalisma?.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoButton1( textColor: Colors.green, textStrokeColor: Colors.transparent, text: "❌ Onaylamıyorum", onPressed: (() { FikoYTService.servisMesaici.ayarlarModel!.refresh(); Navigator.pop( context, ); }), ), ])); }, onLongPress: () { kayit?.value?.ekOdemeler = []; FikoYTService.servisMesaici.aktifCalisma?.refresh(); }, ), const Expanded( child: Divider( indent: 0.0, endIndent: 10.0, thickness: 1, ), ), FikoButton1( text: '➕ Ek Ödemeler', textStrokeColor: Colors.transparent, textColor: Colors.black, onPressed: () { showToolbar.toggle(); }, ), FikoButton1( text: "🗃️", onPressed: () async { kayit?.value?.ekOdemeler = kayit?.value?.bugununAyari.ekOdemeler; FikoYTService.servisMesaici.aktifCalisma?.refresh(); }, ), const Expanded( child: Divider( indent: 10.0, endIndent: 0.0, thickness: 1, ), ), FikoButton1( text: "➕", onPressed: () async { EkOdeme ekOd = EkOdeme(); FikoYTService.dialogGoster( context, SizedBox( width: 250, child: EkOdemeEkle( ekOdeme: ekOd, ), ), FikoDialogAyarlari(baslik: "Ek Ödeme Tanımlama", baslikSimge: "➕", altButonlar: [ FikoButton1( textColor: Colors.green, textStrokeColor: Colors.transparent, text: "Ekle", edgePadding: const EdgeInsets.symmetric(horizontal: 5, vertical: 0), onPressed: (() { List? ekodmler = kayit?.value?.ekOdemeler?.toList() ?? []; ekodmler.add(ekOd); kayit?.value?.ekOdemeler = ekodmler; // FikoYTService.servisMesaici.aktifCalisma?.refresh(); FikoYTService.servisMesaici.aktifCalisma?.refresh(); Navigator.pop( context, ); }), ), const Spacer(), FikoButton1( textColor: Colors.red, textStrokeColor: Colors.transparent, text: "Kapat", edgePadding: const EdgeInsets.symmetric(horizontal: 5, vertical: 0), onPressed: (() { Navigator.pop( context, ); }), ), ]), ); }, ), ], ), /** */ Obx( () => AnimatedSwitcher( duration: const Duration(seconds: 1), child: showToolbar.value == true ? Container( alignment: Alignment.centerLeft, padding: const EdgeInsets.all(1), margin: const EdgeInsets.symmetric(vertical: 5), decoration: BoxDecoration( border: Border.all(color: Colors.grey.shade300), borderRadius: BorderRadius.circular(15), color: Colors.grey.shade100, ), child: SizedBox( height: 18.0, child: ShaderMask( shaderCallback: (Rect rect) { return const LinearGradient( begin: Alignment.centerLeft, end: Alignment.centerRight, colors: [Colors.purple, Colors.transparent, Colors.transparent, Colors.purple], stops: [0.0, 0.1, 0.9, 1.0], // 10% purple, 80% transparent, 10% purple ).createShader(rect); }, blendMode: BlendMode.dstOut, child: SingleChildScrollView( scrollDirection: Axis.horizontal, physics: const BouncingScrollPhysics(), child: Row( children: [ FikoButton1( text: "🧬 Panoya Kopyala", textSize: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), textStrokeWidth: 0, textColor: Colors.black87, textStrokeColor: Colors.transparent, onPressed: () { String data = json.encode(kayit?.value?.ekOdemeler); Clipboard.setData(ClipboardData(text: data)); SnackBar snck = const SnackBar( // behavior: SnackBarBehavior.floating, // margin: EdgeInsets.symmetric(vertical: 50.0, horizontal: 30), dismissDirection: DismissDirection.down, showCloseIcon: true, content: Text('Liste Panoya Kopyalandı'), duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ); ScaffoldMessenger.of(context).showSnackBar(snck); }, ), FikoButton1( text: "📋 Panodan Çek", textSize: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), textStrokeWidth: 0, textColor: Colors.black87, textStrokeColor: Colors.transparent, onPressed: () async { try { List lst = []; dynamic panoData = json.decode((await Clipboard.getData(Clipboard.kTextPlain))?.text ?? "[]"); for (var i = 0; i < panoData.length; i++) { lst.add(EkOdeme.fromJson(panoData[i])); } kayit?.value?.ekOdemeler = lst; FikoYTService.servisMesaici.aktifCalisma?.refresh(); ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('Liste Panodan Kopyalandı'), duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ), ); } catch (e) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: const Text( 'Veri Hatası', style: TextStyle(color: Colors.white), ), backgroundColor: Colors.red, action: SnackBarAction( label: 'Tamam', onPressed: () { // Action butonuna tıklanınca yapılacak işlemler }, ), duration: const Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ), ); } }, ), FikoButton1( text: "💾 Dosyaya Aktar", textSize: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), textStrokeWidth: 0, textColor: Colors.black87, textStrokeColor: Colors.transparent, onPressed: () async { try { String data = json.encode(kayit?.value?.ekOdemeler); // JSON verisini oluştur String jsonString = data; // Dosya kaydetme yerini sor String? outputPath = await FilePicker.platform.saveFile( dialogTitle: 'Kayıt dosyası nereye kaydedilsin?', fileName: 'EkOdemeler.json', bytes: Uint8List.fromList(utf8.encode(data)), ); if (outputPath != null) { if (Platform.isAndroid == false && Platform.isIOS == false) { // Dosyayı yaz File file = File(outputPath); await file.writeAsString(jsonString); } SnackBar snck = const SnackBar( content: Text('Dosya Kaydedildi'), duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ); ScaffoldMessenger.of(context).showSnackBar(snck); } else { SnackBar snck = const SnackBar( content: Text('Dosya Kaydedilmesi İptal Edildi.'), backgroundColor: Colors.red, duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ); ScaffoldMessenger.of(context).showSnackBar(snck); } } catch (e) { SnackBar snck = const SnackBar( content: Text('Bir Hata Oluştu'), backgroundColor: Colors.red, duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ); ScaffoldMessenger.of(context).showSnackBar(snck); } }, ), FikoButton1( text: "📂 Dosyadan Çek", textSize: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), textStrokeWidth: 0, textColor: Colors.black87, textStrokeColor: Colors.transparent, onPressed: () async { try { // Dosya seçme FilePickerResult? result = await FilePicker.platform.pickFiles( dialogTitle: 'Kayıt dosyasını seçin', type: FileType.custom, allowedExtensions: ['json'], // Sadece JSON dosyalarını seçtir ); if (result != null && result.files.single.path != null) { // Dosya yolunu al String filePath = result.files.single.path!; // Dosyanın içeriğini oku File file = File(filePath); String fileContent = await file.readAsString(); // JSON verisini çözümle dynamic jsonList = json.decode(fileContent); List lst = []; for (var i = 0; i < jsonList.length; i++) { lst.add(EkOdeme.fromJson(jsonList[i])); } kayit?.value?.ekOdemeler = lst; FikoYTService.servisMesaici.aktifCalisma?.refresh(); } else {} } catch (e) { SnackBar snck = const SnackBar( content: Text('Bir Hata Oluştu'), backgroundColor: Colors.red, duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ); ScaffoldMessenger.of(context).showSnackBar(snck); } }, ), // FikoButton1( // text: "📡 İnternetten Çek", // textSize: 10, // textAlign: TextAlign.start, // edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), // textStrokeWidth: 0, // textColor: Colors.black87, // textStrokeColor: Colors.transparent, // onPressed: () {}, // ), FikoButton1( text: "🗑️ Tümünü Sil", textSize: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), textStrokeWidth: 0, textColor: Colors.black87, textStrokeColor: Colors.transparent, onPressed: () async { FikoYTService.dialogGoster( context, const Text("Listedeki Tüm Kayıtlar Silinecek.Bu İşlem Geri Alınamaz. Onaylıyormusunuz?"), FikoDialogAyarlari(baslik: "Onay", baslikSimge: "❔", altButonlar: [ FikoButton1( textColor: Colors.green, textStrokeColor: Colors.transparent, text: "✔️ Onaylıyorum", onPressed: () { kayit?.value?.ekOdemeler = []; FikoYTService.servisMesaici.aktifCalisma?.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoButton1( textColor: Colors.red, textStrokeColor: Colors.transparent, text: "❌ Onaylamıyorum", onPressed: (() { FikoYTService.servisMesaici.aktifCalisma?.refresh(); Navigator.pop( context, ); }), ), ])); }, onLongPress: () { kayit?.value?.ekOdemeler = []; FikoYTService.servisMesaici.aktifCalisma?.refresh(); }, ), ], ), ), ), ), ) : null, ), ), /** */ // (kayit?.value?.ekOdemeler ?? []).isEmpty AnimatedCrossFade( crossFadeState: (kayit?.value?.ekOdemeler ?? []).isEmpty ? CrossFadeState.showFirst : CrossFadeState.showSecond, duration: const Duration(milliseconds: 250), firstChild: Padding( padding: const EdgeInsets.only(top: 5), child: Align( alignment: const FractionalOffset(0.5, 0.5), child: Text( "Hiç Ek Ödeme Eklenmemiş", style: TextStyle(fontWeight: FontWeight.bold, color: Colors.red.shade400), textAlign: TextAlign.center, ), ), ).animate( effects: [ const FadeEffect(), const ShimmerEffect(), ], ), secondChild: Column( spacing: 2.0, children: [ for (var i = 0; i < (kayit?.value?.ekOdemeler ?? []).length; i++) Obx( () { EkOdeme? ekOdm = kayit?.value?.ekOdemeler![i]; return FikoButton1( borderColor: Colors.grey.shade200, text: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "${ekOdm?.turu.simge} ${(ekOdm?.ismi ?? 'İsim Verilmemiş')}", ), const Spacer(), FikoButton1( textColor: Colors.white, text: ekOdm?.miktar?.toParaBirimi() ?? 0.0.toParaBirimi(), ), // FikoButton1( // textColor: Colors.amber, // textStrokeColor: Colors.blue, // text: "TL", // ), ], ), textAlign: TextAlign.start, backColor: Colors.black.withOpacity(0.0), edgePadding: const EdgeInsets.symmetric(vertical: 2, horizontal: 5), onPressed: () { FikoYTService.dialogGoster( context, SizedBox( width: 250, child: EkOdemeEkle( ekOdeme: ekOdm, ), ), FikoDialogAyarlari(baslik: "Ek Ödeme Düzenle", baslikSimge: "💎", altButonlar: [ FikoButton1( textColor: Colors.red, textStrokeColor: Colors.transparent, text: "Sil", onPressed: () { List? list0 = kayit?.value?.ekOdemeler!.toList(); list0?.removeAt(i); kayit?.value?.ekOdemeler = list0; // FikoYTService.servisMesaici.aktifCalisma?.refresh(); FikoYTService.servisMesaici.aktifCalisma?.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoButton1( textColor: Colors.green, textStrokeColor: Colors.transparent, text: "Kapat", onPressed: (() { // FikoYTService.servisMesaici.aktifCalisma?.refresh(); FikoYTService.servisMesaici.aktifCalisma?.refresh(); Navigator.pop( context, ); }), ), ]), ); }, ).animate( effects: [const FadeEffect(), ShimmerEffect(delay: 1000.ms)], ); }, ), ], ), ), ], ).animate(effects: [ // FadeEffect(duration: 1000.ms, curve: Curves.easeIn), // ScaleEffect(begin: const Offset(0.2, 0.2),duration: 500.ms, curve: Curves.easeIn), FadeEffect(duration: 1000.ms), SaturateEffect(delay: 1000.ms, duration: 500.ms, curve: Curves.easeIn), BlurEffect( duration: 600.ms, begin: const Offset(3, 3), end: const Offset(0, 0), ), ShimmerEffect( delay: 1000.ms, duration: 1000.ms, curve: Curves.easeIn, ), ]); } }