import 'dart:io'; import 'package:fikoyt_mesaici/apps/mesaici/model/alt_kart/alt_kart.dart'; import 'package:fikoyt_mesaici/core/fikoyt.service.dart'; import 'package:fikoyt_mesaici/core/widgets/yazi_kutulari/yazi_kutulari.dart'; import 'package:fikoyt_ui/fikoyt_ui.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; class AciklamaEkleWidget extends StatefulWidget { AciklamaEkleWidget({ super.key, AltKart? altKart, }) : altKart = altKart ?? AltKart(); final AltKart altKart; @override State createState() => _AciklamaEkleWidgetState(); } class _AciklamaEkleWidgetState extends State { @override Widget build(BuildContext context) { return Column( children: [ if (widget.altKart.ek?.id == null) Center( child: SingleChildScrollView( physics: BouncingScrollPhysics(), scrollDirection: Axis.horizontal, padding: EdgeInsets.symmetric(vertical: 5), child: Row( children: [ FikoYTButton( text: "📷 Resim Ekle", tema: FikoYTButtonTheme( fontSize: 12, textColor: Theme.of(context).extension()?.textColor, backgroundColor: Theme.of(context).extension()?.cardBackgroundColor, borderColor: Colors.blueAccent, ), onPressed: () async { FilePickerResult? result = await FilePicker.platform.pickFiles( allowMultiple: false, type: FileType.image, lockParentWindow: true, ); if (result != null) { File storeImage = File(result.files.first.path!); // use getApplicationDocumentsDirectory() to get a directory inside the app String appDir; // final appDir = await getApplicationDocumentsDirectory(); FikoYTService.programYolu(ekYol: "medya_hareketler"); appDir = await FikoYTService.programYolu(ekYol: "medya_hareketler"); // get the image's directory // copy the image's whole directory to a new // profilResmiSil(); String id = ObjectId().oid; // final File localImage = await storeImage.copy('$appDir$id'); widget.altKart.ek = Ek(); widget.altKart.ek?.id = id; widget.altKart.ek?.turu = EkTuru.RESIM; widget.altKart.ek?.dosyaYolu = storeImage.absolute.path; setState(() {}); } else { // profilResmi.value = null; } }, ), FikoYTButton( text: "📷 Video Ekle", tema: FikoYTButtonTheme( fontSize: 12, textColor: Theme.of(context).extension()?.textColor, backgroundColor: Theme.of(context).extension()?.cardBackgroundColor, borderColor: Colors.blueAccent, ), onPressed: () async { FilePickerResult? result = await FilePicker.platform.pickFiles( allowMultiple: false, type: FileType.video, lockParentWindow: true, ); if (result != null) { File storeImage = File(result.files.first.path!); // use getApplicationDocumentsDirectory() to get a directory inside the app String appDir; // final appDir = await getApplicationDocumentsDirectory(); FikoYTService.programYolu(ekYol: "medya_hareketler"); appDir = await FikoYTService.programYolu(ekYol: "medya_hareketler"); // get the image's directory // copy the image's whole directory to a new // profilResmiSil(); String id = ObjectId().oid; // final File localImage = await storeImage.copy('$appDir$id'); widget.altKart.ek = Ek(); widget.altKart.ek?.id = id; widget.altKart.ek?.turu = EkTuru.VIDEO; widget.altKart.ek?.dosyaYolu = storeImage.absolute.path; setState(() {}); } else { // profilResmi.value = null; } }, ), ], ), ), ), /** */ if (widget.altKart.ek?.id != null && widget.altKart.ek?.turu == EkTuru.RESIM) FutureBuilder( future: FikoYTService.programYolu(ekYol: "medya_hareketler"), builder: (context, snapshot) => snapshot.data != null ? Container( width: double.infinity, height: 150, margin: EdgeInsets.all(5), decoration: BoxDecoration( color: Colors.black, image: DecorationImage( image: FileImage( File("${widget.altKart.ek?.dosyaYolu}"), // File("${snapshot.data}${widget.altKart.ek?.id}"), ), // Resim dosya yolu fit: BoxFit.contain, // Resmin Container'ı kaplaması için cover kullanıyoruz ), ), ) : SizedBox.shrink(), ), if (widget.altKart.ek?.id != null && widget.altKart.ek?.turu == EkTuru.VIDEO) FutureBuilder( future: FikoYTService.programYolu(ekYol: "medya_hareketler"), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.done) { // final videoPath = "${snapshot.data}${widget.altKart.ek?.id}"; final videoPath = "${widget.altKart.ek?.dosyaYolu}"; return SizedBox( // width: 300, // 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()); } }, ), /** */ if (widget.altKart.ek?.id != null) FikoYTButton( text: "📎 Eki Sil", tema: FikoYTButtonTheme( fontSize: 12, textColor: Theme.of(context).extension()?.textColor, backgroundColor: Theme.of(context).extension()?.cardBackgroundColor, borderColor: Colors.blueAccent, ), onPressed: () async { widget.altKart.ek = null; setState(() {}); // String appDir = await FikoYTService.programYolu(ekYol: "medya_hareketler"); // File file = File("$appDir${widget.altKart.ek?.id}"); // try { // if (await file.exists()) { // await file.delete(); // widget.altKart.ek = null; // setState(() {}); // } // } catch (e) { // /// // } }, ), /** */ SizedBox( height: 10, ), SizedBox( // width: 250, child: FikoAciklamaKutusu( baslik: "Açıklama Metni", radius: 5.0, degeri: widget.altKart.aciklama, yaziBoyutu: 12.0, degisti: (value) { widget.altKart.aciklama = value; }, ), ), ], ); } }