import 'dart:convert'; import 'dart:io'; import 'package:fikoyt_mesaici/apps/mesaici/model/ayarlar/model_ayarlar.dart'; import 'package:fikoyt_mesaici/apps/mesaici/model/model_hareketler.dart'; import 'package:fikoyt_mesaici/apps/mesaici/pages/ayarlar/maas_parametreleri/kesinti_ekle.dart'; import 'package:fikoyt_mesaici/core/Extensions/fiko_double_ext.dart'; import 'package:fikoyt_mesaici/core/fikoyt.service.dart'; import 'package:fikoyt_mesaici/core/interface/fiko_dialog_ayarlari.dart'; import 'package:fikoyt_ui/fikoyt_ui.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class KesintilerWidget extends StatelessWidget { KesintilerWidget({super.key, required this.kayit}); // final FikoYTMesaiciService FikoYTService.servisMesaici = Get.put(FikoYTMesaiciService()); final FikoYTService servisFikoYT = FikoYTService(); final Rx? kayit; final RxBool showToolbar = false.obs; @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ FikoYTButton( text: "🗑️", onPressed: () async { FikoYTService.dialogGoster( context, const Text("Aktif Karttaki Tüm Kesintiler Silinecek.Bu İşlem Geri Alınamaz. Onaylıyormusunuz?"), FikoDialogAyarlari(baslik: "Onay", baslikSimge: "❔", altButonlar: [ FikoYTButton( text: "✔️ Onaylıyorum", tema: Theme.of(context).extension()?.copyWith( textColor: Colors.green, textStrokeColor: Colors.transparent, ), onPressed: () { kayit?.value?.calismaKarti?.kesintiler = []; kayit?.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoYTButton( text: "❌ Onaylamıyorum", tema: Theme.of(context).extension()?.copyWith( textColor: Colors.red, textStrokeColor: Colors.transparent, ), onPressed: (() { FikoYTService.servisMesaici.ayarlarModel!.refresh(); Navigator.pop( context, ); }), ), ])); }, onLongPress: () { kayit?.value?.calismaKarti?.kesintiler = []; kayit?.refresh(); }, ), const Expanded( child: Divider( indent: 0.0, endIndent: 10.0, thickness: 1, ), ), FikoYTButton( text: '🔪 Kesintiler', tema: Theme.of(context).extension()?.copyWith( textStrokeColor: Colors.transparent, textColor: Colors.black, fontSize: 10, ), onPressed: () { showToolbar.toggle(); }, ), FikoYTButton( text: "🗃️", onPressed: () async { kayit?.value?.calismaKarti?.kesintiler = kayit?.value?.calismaKarti?.bugununAyari.kesintiler; kayit?.refresh(); }, ), const Expanded( child: Divider( indent: 10.0, endIndent: 0.0, thickness: 1, ), ), FikoYTButton( text: "➕", onPressed: () async { Kesinti ksnt = Kesinti(); FikoYTService.dialogGoster( context, SizedBox( width: 250, child: KesintiEkle( kesinti: ksnt, ), ), FikoDialogAyarlari(baslik: "Kesinti Tanımlama", baslikSimge: "🔪", altButonlar: [ FikoYTButton( text: "Ekle", tema: Theme.of(context).extension()?.copyWith( textColor: Colors.green, textStrokeColor: Colors.transparent, edgePadding: const EdgeInsets.symmetric(horizontal: 5, vertical: 0), ), onPressed: (() { List ksntlr = kayit?.value?.calismaKarti?.kesintiler?.toList() ?? []; ksntlr.add(ksnt); kayit?.value?.calismaKarti?.kesintiler = ksntlr; // kayit?.refresh(); kayit?.refresh(); Navigator.pop( context, ); }), ), const Spacer(), FikoYTButton( text: "Kapat", tema: Theme.of(context).extension()?.copyWith( textColor: Colors.red, textStrokeColor: Colors.transparent, 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: [ FikoYTButton( text: "🧬 Panoya Kopyala", tema: Theme.of(context).extension()?.copyWith( fontSize: 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?.calismaKarti?.kesintiler); 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); }, ), FikoYTButton( text: "📋 Panodan Çek", tema: Theme.of(context).extension()?.copyWith( fontSize: 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(Kesinti.fromJson(panoData[i])); } kayit?.value?.calismaKarti?.kesintiler = lst; kayit?.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 ), ); } }, ), FikoYTButton( text: "💾 Dosyaya Aktar", tema: Theme.of(context).extension()?.copyWith( fontSize: 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?.calismaKarti?.kesintiler); // JSON verisini oluştur String jsonString = data; // Dosya kaydetme yerini sor String? outputPath = await FilePicker.platform.saveFile( dialogTitle: 'Kayıt dosyası nereye kaydedilsin?', fileName: 'Kesintiler.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); } }, ), FikoYTButton( text: "📂 Dosyadan Çek", tema: Theme.of(context).extension()?.copyWith( fontSize: 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(Kesinti.fromJson(jsonList[i])); } kayit?.value?.calismaKarti?.kesintiler = lst; kayit?.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); } }, ), // FikoYTButton( // 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: () {}, // ), FikoYTButton( text: "🗑️ Tümünü Sil", tema: Theme.of(context).extension()?.copyWith( fontSize: 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: [ FikoYTButton( tema: Theme.of(context).extension()?.copyWith( textColor: Colors.green, textStrokeColor: Colors.transparent, ), text: "✔️ Onaylıyorum", onPressed: () { kayit?.value?.calismaKarti?.kesintiler = []; kayit?.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoYTButton( tema: Theme.of(context).extension()?.copyWith( textColor: Colors.red, textStrokeColor: Colors.transparent, ), text: "❌ Onaylamıyorum", onPressed: (() { kayit?.refresh(); Navigator.pop( context, ); }), ), ])); }, onLongPress: () { kayit?.value?.calismaKarti?.kesintiler = []; kayit?.refresh(); }, ), ], ), ), ), ), ) : null, ), ), /** */ // if ((maasObs.value.kesintiler ?? []).isEmpty) AnimatedCrossFade( crossFadeState: (kayit?.value?.calismaKarti?.kesintiler ?? []).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ç Kesinti 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?.calismaKarti?.kesintiler ?? []).length; i++) Obx( () { Kesinti? ksnti_ = kayit?.value?.calismaKarti?.kesintiler![i]; return FikoYTButton( text: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "${ksnti_?.turu.simge} ${(ksnti_?.ismi ?? 'İsim Verilmemiş')}", ), const Spacer(), if (ksnti_?.kesintiSekli == KesintiSekli.SABIT) Row( children: [ FikoYTButton( text: ksnti_?.miktar?.toParaBirimi() ?? 0.0.toParaBirimi(), tema: Theme.of(context).extension()?.copyWith( textColor: Colors.white, borderColor: Colors.grey.shade200, textStrokeColor: Colors.black, ), ), // FikoYTButton( // textColor: Colors.amber, // textStrokeColor: Colors.blue, // text: "TL", // ), ], ), if (ksnti_?.kesintiSekli == KesintiSekli.YUZDELIK) Row( children: [ FikoYTButton( tema: Theme.of(context).extension()?.copyWith( textColor: Colors.white, textStrokeColor: Colors.black, ), text: "${ksnti_?.oran ?? '0.0'}", ), FikoYTButton( tema: Theme.of(context).extension()?.copyWith( textColor: Colors.amber, textStrokeColor: Colors.blue, ), text: "%", ), ], ), if (ksnti_?.kesintiSekli == KesintiSekli.DIGER) Row( children: [ FikoYTButton( tema: Theme.of(context).extension()?.copyWith( textColor: Colors.white, textStrokeColor: Colors.black, ), text: "${ksnti_?.oran ?? '0.0'} % | ${ksnti_?.miktar?.toParaBirimi() ?? 0.0.toParaBirimi()}", ), ], ), ], ), tema: Theme.of(context).extension()?.copyWith( textAlign: TextAlign.start, backgroundColor: Colors.black.withOpacity(0.0), edgePadding: const EdgeInsets.symmetric(vertical: 2, horizontal: 5), ), onPressed: () { FikoYTService.dialogGoster( context, SizedBox( width: 250, child: KesintiEkle( kesinti: ksnti_, ), ), FikoDialogAyarlari(baslik: "Kesinti Düzenle", baslikSimge: "🔪", altButonlar: [ FikoYTButton( tema: Theme.of(context).extension()?.copyWith( textColor: Colors.red, textStrokeColor: Colors.transparent, ), text: "Sil", onPressed: () { List? list0 = kayit?.value?.calismaKarti?.kesintiler?.toList() ?? []; list0.removeAt(i); kayit?.value?.calismaKarti?.kesintiler = list0; // kayit?.refresh(); kayit?.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoYTButton( tema: Theme.of(context).extension()?.copyWith( textColor: Colors.green, textStrokeColor: Colors.transparent, ), text: "Kapat", onPressed: (() { // kayit?.refresh(); kayit?.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, ), ]); } }