import 'dart:io'; import 'package:fikoyt_mesaici/apps/mesaici/model/alt_kart/alt_kart.dart'; import 'package:fikoyt_mesaici/apps/mesaici/model/model_hareketler.dart'; import 'package:fikoyt_mesaici/apps/mesaici/pages/hareketler/pages/alt_hareketler/alt_hareketler.dart'; import 'package:fikoyt_mesaici/apps/mesaici/pages/hareketler/pages/gun_hareketler/aciklama_ekle.dart'; import 'package:fikoyt_mesaici/apps/mesaici/pages/hareketler/pages/gun_hareketler/gun_hareketler.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/fikoyt_ui.dart'; import 'package:fikoyt_ui/ui/fikoyt_card.dart'; import 'package:flutter/material.dart'; // ignore: must_be_immutable class AciklamaKartiWidget extends StatelessWidget { AciklamaKartiWidget({super.key, required this.kayit, this.callState}); Rx? kayit; RxBool siliniyor = false.obs; // final FikoYTMesaiciService FikoYTService.servisMesaici = Get.put(FikoYTMesaiciService()); final PageMesaiciAltHareketlerLogic altKartLogic = Get.put(PageMesaiciAltHareketlerLogic()); final PageMesaiciGunHareketlerLogic gunLogic = Get.put(PageMesaiciGunHareketlerLogic()); final FikoYTService servisFikoYT = FikoYTService(); dynamic callState; @override Widget build(BuildContext context) { return // Container( // width: double.infinity, // padding: const EdgeInsets.all(0), // constraints: const BoxConstraints(minHeight: 41), // alignment: Alignment.topLeft, // decoration: BoxDecoration(color: Colors.white, border: Border.all(color: Colors.blue.shade400, width: 1), borderRadius: BorderRadius.circular(5)), // margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 3), // child: Column( // children: [ FikoYTCard( children: [ Stack( children: [ Flex( direction: Axis.horizontal, children: [ Text('💬 '), Spacer(), FikoYTButton( text: "Açıklama Kartı", tema: Theme.of(context).extension()?.copyWith( fontSize: 12, textStrokeColor: Colors.transparent, fontWeight: FontWeight.w800, textAlign: TextAlign.left, textColor: Theme.of(context).extension()?.textColor, ), ), Spacer(), ], ), Positioned( right: 0, child: FikoYTButton( text: "${kayit?.value?.kayitTarih?.formatla('dd.MM.yyyy HH:mm:ss') ?? kayit?.value?.tarih?.formatla('dd.MM.yyyy')}", tema: Theme.of(context).extension()?.copyWith( fontSize: 10, textStrokeColor: Colors.transparent, fontWeight: FontWeight.normal, textAlign: TextAlign.left, textColor: Theme.of(context).extension()?.successTextColor, ), ), ), ], ), const Divider( height: 2, ), if (kayit?.value?.altKart?.ek?.id != null && kayit?.value?.altKart?.ek?.turu == EkTuru.RESIM) FutureBuilder( future: FikoYTService.programYolu(ekYol: "medya_hareketler"), builder: (context, snapshot) => snapshot.data != null ? Container( width: double.infinity, margin: EdgeInsets.all(2), height: 150, decoration: BoxDecoration( color: Colors.black, image: DecorationImage( image: FileImage( // File("${snapshot.data}${kayit?.value?.altKart?.ek?.id}"), File("${snapshot.data}${kayit?.value?.altKart?.ek?.dosyaYolu}"), ), // Resim dosya yolu fit: BoxFit.contain, // Resmin Container'ı kaplaması için cover kullanıyoruz ), ), ) : SizedBox.shrink(), ), if (kayit?.value?.altKart?.ek?.id != null && kayit?.value?.altKart?.ek?.turu == EkTuru.VIDEO) FutureBuilder( future: FikoYTService.programYolu(ekYol: "medya_hareketler"), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.done) { // final videoPath = "${snapshot.data}${kayit?.value?.altKart?.ek?.id}"; final videoPath = "${kayit?.value?.altKart?.ek?.dosyaYolu}"; return SizedBox( width: double.infinity, // Sabit bir genişlik belirleyin height: 200, // Sabit bir yükseklik belirleyin child: FikoYTVideoPlayer( videoFilePath: videoPath, autoPlay: false, showControls: true, showControlsOnInitialize: true, showOptions: false, loop: false, )); } else { return Center(child: CircularProgressIndicator()); } }, ), SizedBox( height: 10, ), Container( width: double.infinity, // alignment: Alignment.topLeft, padding: const EdgeInsets.all(5), constraints: const BoxConstraints(minHeight: 40), child: Text( "${(kayit?.value?.altKart?.aciklama ?? '').isEmpty ? 'Açıklama Yok' : kayit?.value?.altKart?.aciklama}", style: TextStyle( fontSize: 12, color: Theme.of(context).extension()?.textColor, ), ), // FikoYTButton( // text: "${(kayit?.value?.altKart?.aciklama ?? '').isEmpty ? 'Açıklama Yok' : kayit?.value?.altKart?.aciklama}", // tema: Theme.of(context).extension()?.copyWith( // fontSize: 12, // textStrokeColor: Colors.transparent, // fontWeight: FontWeight.normal, // textAlign: TextAlign.left, // // textColor: Colors.black, // ), // ), ), const Divider( height: 2, ), Padding( padding: const EdgeInsets.all(5), child: Row( children: [ FikoYTButton( text: "✏️ Düzenle", tema: FikoYTButtonTheme( backgroundColor: Colors.blue, textColor: Colors.white, fontSize: 12, ), onPressed: () { AltKart altKart1 = kayit!.value!.altKart!; aciklamaDuzenle(context, altKart1).then( (value) async { if (value == null) return; /** */ await FikoYTService.servisMesaici.isar?.writeTxn( () async { ModelHareketler altHrkt = kayit!.value!; // altHrkt.tarih = DateTime(2024).formattan("dd.MM.yyyy EEEE", kayit!.value!.kayitTarih!.formatla("dd.MM.yyyy EEEE")); altHrkt.kayitTarih = DateTime.now(); AltKart altKart = AltKart(); altKart.aciklama = value.aciklama ?? ""; altKart.ek = value.ek; altHrkt.altKart = altKart; // altKart.ustKartid = logic.hareketler.value?.id; // logic.aktifHareket.value?.altKartlar.clear(); // logic.hareketler.value?.altKartlar.add(altHrkt); // await isar.writeTxn(() async { await FikoYTService.servisMesaici.isar?.modelHareketlers.put(altHrkt); // altHrkt.ustKart.value = logic.hareketler.value; // await altHrkt.ustKart.save(); // if (callState != null) await callState(); // await logic.hareketler.value?.altKartlar.save(); if (callState != null) { callState(); } await altKartLogic.alAktifHareket(); altKartLogic.aktifHareket.refresh(); }, ); // }); }, ); }, ), const Spacer(), /** */ TextButton( onPressed: () async { if (siliniyor.value == true) return; siliniyor.value = true; siliniyor.refresh(); try { await FikoYTService.servisMesaici.isar?.writeTxn( () async { await Future.delayed(const Duration(milliseconds: 1000)); if (kayit?.value != null) { await FikoYTService.servisMesaici.isar?.modelHareketlers.delete(kayit!.value!.id); if (kayit?.value?.altKart?.ek?.id != null) { String appDir = await FikoYTService.programYolu(ekYol: "medya_hareketler"); File file = File("$appDir${kayit?.value?.altKart?.ek?.id}"); try { if (await file.exists()) { await file.delete(); } } catch (e) { /// } } ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text( 'Kart Silindi.', style: TextStyle(color: Colors.white), ), backgroundColor: Colors.red, duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ), ); } }, ); siliniyor.value = false; siliniyor.refresh(); kayit?.refresh(); } catch (e) { // print(e); siliniyor.value = false; siliniyor.refresh(); } finally { siliniyor.value = false; siliniyor.refresh(); if (callState != null) { callState(); } await altKartLogic.alAktifHareket(); altKartLogic.aktifHareket.refresh(); } }, style: TextButton.styleFrom( alignment: Alignment.center, fixedSize: const Size.fromHeight(16), backgroundColor: Colors.red.shade400, shape: const RoundedRectangleBorder( borderRadius: BorderRadius.horizontal( left: Radius.circular(50), right: Radius.circular(50), ), ), textStyle: const TextStyle( fontSize: 10, color: Colors.white, ), ), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 10), child: Obx( () => AnimatedCrossFade( firstChild: const Text( "💾 Sil", style: TextStyle( color: Colors.white, ), ), secondChild: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 16, height: 16, padding: const EdgeInsets.all(2.0), child: const CircularProgressIndicator( color: Colors.white, strokeWidth: 3, ), ), ], ), crossFadeState: siliniyor.value ? CrossFadeState.showSecond : CrossFadeState.showFirst, duration: const Duration(milliseconds: 500), ), ), ), ), ], ), /** */ ), ], ).animate(effects: [const FadeEffect()]); } Future aciklamaDuzenle(BuildContext context, AltKart altKart) async { return FikoYTService.dialogGoster( context, AciklamaEkleWidget( altKart: altKart, ), FikoDialogAyarlari(baslik: "Açıklama Düzenle", baslikSimge: "➕", arkaPlanaTiklanincaKapansin: false, altButonlar: [ FikoYTButton( text: "Kaydet", tema: Theme.of(context).extension()?.copyWith( textColor: Colors.green, textStrokeColor: Colors.transparent, edgePadding: const EdgeInsets.symmetric(horizontal: 5, vertical: 0), ), onPressed: (() { Navigator.pop(context, altKart); }), ), 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); }), ), ]), ); } }