import 'dart:convert'; import 'dart:io'; import 'package:fikoyt_mesaici/apps/mesaici/model/calisma_kayit/calisma_kayit.dart'; import 'package:fikoyt_mesaici/apps/mesaici/model/ayarlar/model_ayarlar.dart'; import 'package:fikoyt_mesaici/apps/mesaici/widgets/aktif_kart/saat_tablosu/mola_ekle_dialog.dart'; import 'package:fikoyt_mesaici/core/Extensions/fiko_duration_ext.dart'; import 'package:fikoyt_mesaici/core/Extensions/fiko_tarih.dart'; import 'package:fikoyt_mesaici/core/fikoyt.service.dart'; import 'package:fikoyt_mesaici/core/interface/fiko_dialog_ayarlari.dart'; import 'package:fikoyt_ui/ui/ui.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 servisMesaici = Get.put(FikoYTMesaiciService()); FikoYTService servisFikoYT = FikoYTService(); @override Widget build(BuildContext context) { return Obx( () => 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?.gecerliMolalariAl(); kayit?.refresh(); }, ), ], ), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ const Expanded( child: Divider( indent: 20.0, endIndent: 10.0, thickness: 1, ), ), Text( 'Molalar (${kayit?.value?.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?.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: [ FikoButton( tema: FikoButtonTema( yaziRengi: Colors.green, yaziSinirRengi: Colors.transparent, ), text: "Ekle", onPressed: (() { List? list0 = kayit?.value?.molalar?.toList() ?? []; list0.add(ml.value); kayit?.value?.molalar = list0; kayit?.refresh(); kayit?.refresh(); Navigator.pop( context, ); }), ), const Spacer(), FikoButton( tema: FikoButtonTema( yaziRengi: Colors.red, yaziSinirRengi: 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: Theme.of(context).extension()?.kartArkaPlanRenk, ), 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: [ FikoButton( text: "🧬 Panoya Kopyala", tema: FikoButtonTema( boyutYazi: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), boyutYaziSinir: 0, // textColor: Colors.black87, yaziSinirRengi: Colors.transparent, ), onPressed: () { String data = json.encode(kayit?.value?.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); }, ), FikoButton( text: "📋 Panodan Çek", tema: FikoButtonTema( boyutYazi: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), boyutYaziSinir: 0, // textColor: Colors.black87, yaziSinirRengi: 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!.tarih!); ml.cikisSaati = ml.cikisSaati?.ayarlaTarih(kayit!.value!.tarih!); lstMl.add(ml); } kayit?.value?.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 ), ); } }, ), FikoButton( text: "💾 Dosyaya Aktar", tema: FikoButtonTema( boyutYazi: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), boyutYaziSinir: 0, // textColor: Colors.black87, yaziSinirRengi: Colors.transparent, ), onPressed: () async { try { String data = json.encode(kayit?.value?.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); } }, ), FikoButton( text: "📂 Dosyadan Çek", tema: FikoButtonTema( boyutYazi: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), boyutYaziSinir: 0, // textColor: Colors.black87, yaziSinirRengi: 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!.tarih!); ml.cikisSaati = ml.cikisSaati?.ayarlaTarih(kayit!.value!.tarih!); lstMl.add(ml); } kayit?.value?.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: () {}, // ), FikoButton( text: "🗑️ Tümünü Sil", tema: FikoButtonTema( boyutYazi: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), boyutYaziSinir: 0, // textColor: Colors.black87, yaziSinirRengi: 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: [ FikoButton( tema: FikoButtonTema( yaziRengi: Colors.green, yaziSinirRengi: Colors.transparent, ), text: "✔️ Onaylıyorum", onPressed: () { kayit?.value?.molalar = []; kayit?.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoButton( tema: FikoButtonTema( yaziRengi: Colors.red, yaziSinirRengi: Colors.transparent, ), text: "❌ Onaylamıyorum", onPressed: (() { kayit?.refresh(); Navigator.pop( context, ); }), ), ])); }, onLongPress: () { kayit?.value?.molalar = []; kayit?.refresh(); }, ), ], ), ), ), ), ), /** * */ /** */ (kayit?.value?.molalar ?? []).isEmpty ? 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)]) : Column( spacing: 5.0, children: [ for (var i = 0; i < (kayit?.value?.molalar ?? []).length; i++) Obx( () { Rx? mola = kayit?.value?.molalar![i].obs; return FikoButton( text: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Text(mola?.value.molaDurumu == MolaDurumu.YASANIYOR ? "👉🏻" : ""), Text( '☕ ${mola?.value.ismi ?? 'İsim Verilmemiş'}', ), const Spacer(), FikoButton( text: "${mola?.value.farkHesapla().insanize ?? 'Yok'}", tema: FikoButtonTema( yaziRengi: Colors.white, yaziSinirRengi: Colors.black, ), ), ], ), tema: FikoButtonTema( textAlign: TextAlign.start, 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: [ FikoButton( tema: FikoButtonTema( yaziRengi: Colors.red, yaziSinirRengi: Colors.transparent, ), text: "Sil", onPressed: () { List? list0 = kayit?.value?.molalar!.toList() ?? []; list0.removeAt(i); kayit?.value?.molalar = list0; kayit?.refresh(); kayit?.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoButton( tema: FikoButtonTema( yaziRengi: Colors.green, yaziSinirRengi: Colors.transparent, ), text: "Kapat", onPressed: (() { kayit?.refresh(); Navigator.pop( context, ); }), ), ]), ); }, ).animate( effects: [const FadeEffect(), ShimmerEffect(delay: 1000.ms)], ); }, ), ], ), // SizedBox( // height: 55, // 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: ListView( // shrinkWrap: true, // physics: const BouncingScrollPhysics(), // // scrollDirection: Axis.horizontal, // // your ListView // children: [ // for (var k = 0; k < (kayit?.value?.molalar ?? []).length; k++) // Obx(() { // // Mola mola = // // gunObs.value.molalar[k]; // Rx? molaObs = kayit?.value?.molalar![k].obs; // molaObs?.listen((val) { // kayit?.value?.molalar![k] = val; // kayit?.refresh(); // kayit?.refresh(); // }); // return Padding( // padding: const EdgeInsets.symmetric( // horizontal: 4, // ), // child: ChoiceChip( // avatar: Image.asset( // 'assets/mesaici/ayarlar/cay.png', // // width: 300, // width: 40, // height: 40, // fit: BoxFit.contain, // ), // padding: const EdgeInsets.all(3), // label: Column( // children: [ // Align( // alignment: Alignment.centerLeft, // child: Obx( // () => Text( // (molaObs?.value.ismi == "" && molaObs?.value.ismi == null) ? "İsim Verilmemiş" : molaObs?.value.ismi ?? "İsim Verilmemiş", // style: const TextStyle( // fontSize: 12, // ), // textAlign: TextAlign.start, // ), // ), // ), // Row( // crossAxisAlignment: CrossAxisAlignment.center, // children: [ // FikoButton1(text: molaObs?.value.girisSaati?.formatla("HH:mm:ss") ?? "Yok", textSize: 10, textColor: Colors.green, textStrokeColor: Colors.transparent), // FikoButton1( // text: molaObs?.value.cikisSaati?.formatla("HH:mm:ss") ?? "Yok", // textSize: 10, // textColor: Colors.red, // textStrokeColor: Colors.transparent, // ), // ], // ), // Row( // crossAxisAlignment: CrossAxisAlignment.center, // mainAxisAlignment: MainAxisAlignment.center, // children: [ // FikoButton1( // text: molaObs?.value.farkHesapla().insanize ?? 'Yok', // textSize: 14, // textColor: Colors.green, // textStrokeColor: Colors.transparent, // ), // ], // ), // ], // ), // checkmarkColor: Colors.transparent, // backgroundColor: Colors.transparent, // showCheckmark: false, // selected: false, // onSelected: (bool selected) { // FikoYTService.dialogGoster( // context, // SizedBox( // width: 250, // child: MolaDialog( // mola: molaObs!.value, // ), // ), // FikoDialogAyarlari(baslik: "Mola Düzenle", altButonlar: [ // FikoButton1( // textColor: Colors.red, // textStrokeColor: Colors.transparent, // text: "Sil", // onPressed: () { // List? list0 = kayit?.value?.molalar?.toList() ?? []; // list0.remove(molaObs.value); // kayit?.value?.molalar = list0; // kayit?.refresh(); // kayit?.refresh(); // Navigator.pop( // context, // ); // }, // ), // const Spacer(), // FikoButton1( // textColor: Colors.green, // textStrokeColor: Colors.transparent, // text: "Kapat", // onPressed: (() { // // print(molaObs.value.toJson()); // molaObs.refresh(); // 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, ), ]); } }