import 'dart:convert'; import 'dart:io'; import 'package:fikoyt_mesaici/apps/mesaici/base_page_mesaici_view.dart'; import 'package:fikoyt_mesaici/apps/mesaici/model/ayarlar/model_ayarlar.dart'; import 'package:fikoyt_mesaici/apps/mesaici/pages/ayarlar/maas_parametreleri/kesinti_ekle.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'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:get/get.dart'; class KesintilerWidget extends StatelessWidget { KesintilerWidget({super.key, required this.kayit}); BasePageMesaiciLogic basePageMesaiciLogic = Get.put(BasePageMesaiciLogic()); // final FikoYTMesaiciService FikoYTService.servisMesaici = Get.put(FikoYTMesaiciService()); final FikoYTService servisFikoYT = FikoYTService(); Rx kayit; final RxBool showToolbar = false.obs; @override Widget build(BuildContext context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ const Expanded( child: Divider( indent: 20.0, endIndent: 10.0, thickness: 1, ), ), FikoButton( text: '🔪 Kesintiler', tema: FikoButtonTema( boyutYazi: 10, yaziSinirRengi: Colors.transparent, yaziRengi: Theme.of(context).extension()?.yaziRengi, ), onPressed: () { showToolbar.toggle(); }, ), 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 { Kesinti ksnt = Kesinti(); FikoYTService.dialogGoster( context, SizedBox( width: 250, child: KesintiEkle( kesinti: ksnt, ), ), FikoDialogAyarlari(baslik: "Kesinti Tanımlama", baslikSimge: "🔪", altButonlar: [ FikoButton( text: "Ekle", tema: FikoButtonTema( edgePadding: const EdgeInsets.symmetric(horizontal: 5, vertical: 0), yaziRengi: Colors.green, yaziSinirRengi: Colors.transparent, ), onPressed: (() { List ksntlr = kayit.value.kesintiler?.toList() ?? []; ksntlr.add(ksnt); kayit.value.kesintiler = ksntlr; FikoYTService.servisMesaici.ayarlarModel!.refresh(); Navigator.pop( context, ); }), ), const Spacer(), FikoButton( text: "Kapat", tema: FikoButtonTema( edgePadding: const EdgeInsets.symmetric(horizontal: 5, vertical: 0), yaziRengi: Colors.red, yaziSinirRengi: Colors.transparent, ), onPressed: (() { Navigator.pop( context, ); }), ), ]), ); }, child: const Text("➕"), // const Icon(Icons.notifications, // color: Colors.lightBlue, size: 14), ), ), ], ), /** */ 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: 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, yaziRengi: Colors.black87, yaziSinirRengi: Colors.transparent, ), onPressed: () { String data = json.encode(kayit.value.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); }, ), FikoButton( text: "📋 Panodan Çek", tema: FikoButtonTema( boyutYazi: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), boyutYaziSinir: 0, yaziRengi: Colors.black87, yaziSinirRengi: 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.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 ), ); } }, ), FikoButton( text: "💾 Dosyaya Aktar", tema: FikoButtonTema( boyutYazi: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), boyutYaziSinir: 0, yaziRengi: Colors.black87, yaziSinirRengi: Colors.transparent, ), onPressed: () async { try { String data = json.encode(kayit.value.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); } }, ), FikoButton( text: "📂 Dosyadan Çek", tema: FikoButtonTema( boyutYazi: 10, textAlign: TextAlign.start, edgePadding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 5), boyutYaziSinir: 0, yaziRengi: 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 dynamic jsonList = json.decode(fileContent); List lst = []; for (var i = 0; i < jsonList.length; i++) { lst.add(Kesinti.fromJson(jsonList[i])); } kayit.value.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); } }, ), // 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, yaziRengi: 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( text: "✔️ Onaylıyorum", tema: FikoButtonTema( yaziRengi: Colors.green, yaziSinirRengi: Colors.transparent, ), onPressed: () { kayit.value.kesintiler = []; kayit.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoButton( text: "❌ Onaylamıyorum", tema: FikoButtonTema( yaziRengi: Colors.red, yaziSinirRengi: Colors.transparent, ), onPressed: (() { kayit.refresh(); Navigator.pop( context, ); }), ), ])); }, onLongPress: () { kayit.value.kesintiler = []; kayit.refresh(); }, ), ], ), ), ), ), ) : null, ), ), /** */ // if ((maasObs.value.kesintiler ?? []).isEmpty) AnimatedCrossFade( crossFadeState: (kayit.value.kesintiler ?? []).isEmpty ? CrossFadeState.showFirst : CrossFadeState.showSecond, duration: const Duration(milliseconds: 250), firstChild: Padding( padding: const EdgeInsets.only(top: 30.0), child: Stack( children: [ Card( child: Container( height: 100.0, ), ), const FractionalTranslation( translation: Offset(0.0, -0.4), child: Align( alignment: FractionalOffset(0.5, 0.0), child: CircleAvatar( // backgroundColor: Colors.redAccent.shade200, radius: 25.0, child: Text( "🔪", style: TextStyle(fontSize: 36), ), ), ), ), Padding( padding: const EdgeInsets.only(top: 48), child: Align( alignment: const FractionalOffset(0.5, 0.5), child: Text( "Hiç Kesinti Eklenmemiş", style: TextStyle(fontSize: 14, fontWeight: FontWeight.normal, color: Colors.blueAccent.shade400), textAlign: TextAlign.center, ), ), ), ], ), ), secondChild: Column( spacing: 5.0, children: [ for (var i = 0; i < (kayit.value.kesintiler ?? []).length; i++) Obx( () { Kesinti ksnti_ = kayit.value.kesintiler![i]; return FikoButton1( 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: [ FikoButton( text: "${ksnti_.miktar ?? '0.0'}", tema: FikoButtonTema( yaziRengi: Colors.white, yaziSinirRengi: Colors.black, ), ), FikoButton( text: "TL", tema: FikoButtonTema( yaziRengi: Colors.amber, yaziSinirRengi: Colors.blue, ), ), ], ), if (ksnti_.kesintiSekli == KesintiSekli.YUZDELIK) Row( children: [ FikoButton( text: "${ksnti_.oran ?? '0.0'}", tema: FikoButtonTema( yaziRengi: Colors.white, yaziSinirRengi: Colors.black, ), ), FikoButton( text: "%", tema: FikoButtonTema( yaziRengi: Colors.amber, yaziSinirRengi: Colors.blue, ), ), ], ), if (ksnti_.kesintiSekli == KesintiSekli.DIGER) Row( children: [ FikoButton( text: "${ksnti_.oran ?? '0.0'}% | ${ksnti_.miktar ?? '0.0'} TL ", tema: FikoButtonTema( yaziRengi: Colors.white, yaziSinirRengi: Colors.black, ), ), ], ), ], ), 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: KesintiEkle( kesinti: ksnti_, ), ), FikoDialogAyarlari(baslik: "Kesinti Düzenle", baslikSimge: "💎", altButonlar: [ FikoButton1( textColor: Colors.red, textStrokeColor: Colors.transparent, text: "Sil", onPressed: () { List? list0 = kayit.value.kesintiler?.toList() ?? []; list0.removeAt(i); kayit.value.kesintiler = list0; FikoYTService.servisMesaici.ayarlarModel!.refresh(); Navigator.pop( context, ); }, ), const Spacer(), FikoButton1( textColor: Colors.green, textStrokeColor: Colors.transparent, text: "Kapat", onPressed: (() { FikoYTService.servisMesaici.ayarlarModel!.refresh(); Navigator.pop( context, ); }), ), ]), ); }, ).animate( effects: [const FadeEffect(), ShimmerEffect(delay: 1000.ms)], ); }, ), ], ), ), ], ); } }