import 'dart:convert'; import 'dart:io'; import 'package:fikoyt_akcali/apps/finans/model/ayarlar/model_ayarlar.dart'; import 'package:fikoyt_akcali/apps/finans/model/model_hareketler.dart'; import 'package:fikoyt_akcali/apps/finans/widgets/aktif_kart/saat_tablosu/mola_ekle_dialog.dart'; import 'package:fikoyt_akcali/core/Extensions/fiko_duration_ext.dart'; import 'package:fikoyt_akcali/core/Extensions/fiko_tarih.dart'; import 'package:fikoyt_akcali/core/fikoyt.service.dart'; import 'package:fikoyt_akcali/core/interface/fiko_dialog_ayarlari.dart'; import 'package:fikoyt_akcali/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'; class MolalarWidget extends StatelessWidget { MolalarWidget({super.key, required this.kayit}); final Rx? kayit; // FikoYTMesaiciService FikoYTService.servisMesaici = Get.put(FikoYTMesaiciService()); FikoYTService servisFikoYT = FikoYTService(); @override Widget build(BuildContext context) { return Column( children: [ Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ FikoButton1( text: "⏳ Geçerli Molalar", textSize: 10, edgePadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 1), textColor: Colors.black, textStrokeColor: Colors.transparent, borderColor: Colors.blue, onPressed: () { kayit?.value?.calismaKarti?.gecerliMolalariAl(); kayit?.refresh(); }, ), ], ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ const Expanded( child: Divider( indent: 20.0, endIndent: 10.0, thickness: 1, ), ), Obx( () => Text( 'Molalar (${kayit?.value?.calismaKarti?.molalar?.toplamMola.insanize ?? 'Yok'})', style: const TextStyle( fontWeight: FontWeight.bold, ), ), ), const Expanded( child: Divider( indent: 10.0, endIndent: 20.0, thickness: 1, ), ), SizedBox( width: 33, child: MaterialButton( elevation: 0, minWidth: 0, shape: CircleBorder( // borderRadius: // const BorderRadius.all( // Radius.circular(5)), side: BorderSide(width: 1, color: Colors.blue.withOpacity(0.5), style: BorderStyle.solid), ), padding: const EdgeInsets.all(0), // color: Colors.white, onPressed: () async { Rx ml = Mola().obs; ml.value.girisSaati = kayit?.value?.calismaKarti?.tarih; ml.value.cikisSaati = null; FikoYTService.dialogGoster( context, SizedBox( width: 250, // height: 300, child: MolaEkleDialog( mola: ml, ayarGizle: true, ), ), FikoDialogAyarlari(baslik: "Mola Ekle", baslikSimge: "➕", altButonlar: [ FikoButton1( textColor: Colors.green, textStrokeColor: Colors.transparent, text: "Ekle", onPressed: (() { List? list0 = kayit?.value?.calismaKarti?.molalar?.toList() ?? []; list0.add(ml.value); kayit?.value?.calismaKarti?.molalar = list0; // kayit?.refresh(); // kayit?.refresh(); Navigator.pop( context, ); }), ), const Spacer(), FikoButton1( textColor: Colors.red, textStrokeColor: Colors.transparent, text: "Kapat", onPressed: (() { Navigator.pop( context, ); }), ), ]), ); }, child: const Text("➕"), // const Icon(Icons.notifications, // color: Colors.lightBlue, size: 14), ), ), ], ), /*** * */ 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?.calismaKarti?.molalar); 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 lstMl = []; dynamic panoData = json.decode((await Clipboard.getData(Clipboard.kTextPlain))?.text ?? "{}"); for (var i = 0; i < panoData.length; i++) { Mola ml = Mola.fromJson(panoData[i]); ml.girisSaati = ml.girisSaati?.ayarlaTarih(kayit!.value!.calismaKarti!.tarih!); ml.cikisSaati = ml.cikisSaati?.ayarlaTarih(kayit!.value!.calismaKarti!.tarih!); lstMl.add(ml); } kayit?.value?.calismaKarti?.molalar = lstMl; 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 ), ); } }, ), 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?.calismaKarti?.molalar); // JSON verisini oluştur String jsonString = data; // Dosya kaydetme yerini sor String? outputPath = await FilePicker.platform.saveFile( dialogTitle: 'Kayıt dosyası nereye kaydedilsin?', fileName: 'Molalar.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 List lstMl = []; dynamic panoData = json.decode(fileContent); for (var i = 0; i < panoData.length; i++) { Mola ml = Mola.fromJson(panoData[i]); ml.girisSaati = ml.girisSaati?.ayarlaTarih(kayit!.value!.calismaKarti!.tarih!); ml.cikisSaati = ml.cikisSaati?.ayarlaTarih(kayit!.value!.calismaKarti!.tarih!); lstMl.add(ml); } kayit?.value?.calismaKarti?.molalar = lstMl; 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); } }, ), // 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?.calismaKarti?.molalar = []; kayit?.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoButton1( textColor: Colors.red, textStrokeColor: Colors.transparent, text: "❌ Onaylamıyorum", onPressed: (() { kayit?.refresh(); Navigator.pop( context, ); }), ), ])); }, onLongPress: () { kayit?.value?.calismaKarti?.molalar = []; kayit?.refresh(); }, ), ], ), ), ), ), ), /** * */ /** */ Obx( () => Visibility( visible: (kayit?.value?.calismaKarti?.molalar ?? []).isEmpty, child: Padding( padding: const EdgeInsets.only(top: 30.0), child: Stack( children: [ Card( child: Container( height: 60.0, ), ), FractionalTranslation( translation: const Offset(0.0, -0.4), child: Align( alignment: const FractionalOffset(0.5, 0.0), child: CircleAvatar( // backgroundColor: Colors.redAccent.shade200, radius: 25.0, child: Image.asset( 'assets/mesaici/ayarlar/cay.png', // width: 300, width: 42, height: 42, fit: BoxFit.contain, ), ), ), ), Padding( padding: const EdgeInsets.only(top: 30), child: Align( alignment: const FractionalOffset(0.5, 0.5), child: Text( "Henüz Mola Kaydı Girilmemiş", style: TextStyle(fontSize: 14, fontWeight: FontWeight.w300, color: Colors.blueAccent.shade400), textAlign: TextAlign.center, ), ), ), ], ), ).animate(effects: [const FadeEffect(), ShimmerEffect(delay: 1000.ms)]), ), ), Obx( () => Visibility( visible: (kayit?.value?.calismaKarti?.molalar ?? []).isNotEmpty, child: Column( spacing: 5.0, children: [ for (var i = 0; i < (kayit?.value?.calismaKarti?.molalar ?? []).length; i++) Obx( () { Rx? mola = kayit?.value?.calismaKarti?.molalar![i].obs; return FikoButton1( text: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Text(mola?.value.molaDurumu == MolaDurumu.YASANIYOR ? "👉🏻" : ""), Text( '☕ ${mola?.value.ismi ?? 'İsim Verilmemiş'}', ), const Spacer(), FikoButton1( textColor: Colors.white, textStrokeColor: Colors.black, text: "${mola?.value.farkHesapla().insanize ?? 'Yok'}", ), ], ), textAlign: TextAlign.start, // backColor: mola?.value.molaDurumu == MolaDurumu.YASANDI // ? Colors.greenAccent // : mola?.value.molaDurumu == MolaDurumu.YASANIYOR // ? Colors.amber // : Colors.transparent, edgePadding: const EdgeInsets.symmetric(vertical: 2, horizontal: 5), onPressed: () { FikoYTService.dialogGoster( context, SizedBox( width: 250, child: MolaEkleDialog( mola: mola!, ayarGizle: true, ), ), FikoDialogAyarlari(baslik: "Mola Düzenle", baslikSimge: "🕙", altButonlar: [ FikoButton1( textColor: Colors.red, textStrokeColor: Colors.transparent, text: "Sil", onPressed: () { List? list0 = kayit?.value?.calismaKarti?.molalar!.toList() ?? []; list0.removeAt(i); kayit?.value?.calismaKarti?.molalar = list0; kayit?.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoButton1( textColor: Colors.green, textStrokeColor: Colors.transparent, text: "Kapat", onPressed: (() { 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, ), ]); } }