// ignore_for_file: library_private_types_in_public_api import 'dart:async'; import 'dart:io'; import 'dart:typed_data'; import 'package:archive/archive_io.dart'; import 'package:fikoyt_mesaici/apps/mesaici/model/ayarlar/model_ayarlar.dart'; import 'package:fikoyt_mesaici/core/Extensions/fiko_tarih.dart'; import 'package:fikoyt_mesaici/core/fikoyt.service.dart'; import 'package:fikoyt_ui/fikoyt_ui.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import '../../../../core/widgets/base_page/base_page_view.dart'; import '../../../../core/widgets/fikoyt_elastic/fikoyt_elastic.dart'; import '../../widgets/kullanici_bilgi_navigasyon/kullanici_bilgi_navigasyon.dart'; import '../../widgets/uygulama_baslik/uygulama_baslik.dart'; class PageMesaiciYedeklemeLogic extends GetxController { // final FikoYTMesaiciService servisMesaici = Get.put(FikoYTMesaiciService()); RxBool gosterVeriEkleyici = false.obs; RxBool simdiYedekleniyor = false.obs; RxBool dosyadanYukleniyor = false.obs; RxString yuklenenItem = "".obs; /** */ @override void onInit() { // TODO: implement onInit super.onInit(); } Future yedekleVeZiple({required List dizinler, required String zipDosyasiYolu, required Function(double) ilerlemeCallback}) async { try { Archive archive = Archive(); int toplamDosyaSayisi = 0; int islenenDosyaSayisi = 0; // Ortak kök yolunu hesapla String ortakKokYol = dizinler.reduce((value, element) { List valueParts = value.split(Platform.pathSeparator); List elementParts = element.split(Platform.pathSeparator); int minLength = valueParts.length < elementParts.length ? valueParts.length : elementParts.length; List commonParts = []; for (int i = 0; i < minLength; i++) { if (valueParts[i] == elementParts[i]) { commonParts.add(valueParts[i]); } else { break; } } return commonParts.join(Platform.pathSeparator); }); // Tüm dosyaların sayısını belirliyoruz for (String dizin in dizinler) { Directory dir = Directory(dizin); if (await dir.exists()) { await for (var file in dir.list(recursive: true, followLinks: false)) { if (file is File) { toplamDosyaSayisi++; } } } else { throw Exception('Dizin mevcut değil: $dizin'); } } // Dosyaları ve klasörleri ZIP'e ekliyoruz for (String dizin in dizinler) { Directory dir = Directory(dizin); if (await dir.exists()) { await for (var file in dir.list(recursive: true, followLinks: false)) { if (file is File) { try { // Dosyanın içeriğini al List? fileBytes = await file.readAsBytes(); // Göreceli yol String relativePath = file.path.replaceFirst(ortakKokYol, '').replaceAll('\\', '/'); // Normalize et // ZIP'e ekle archive.addFile(ArchiveFile.noCompress( relativePath, // Klasör yapısını korur file.lengthSync(), fileBytes ?? [], )); // İlerleme durumunu güncelle islenenDosyaSayisi++; double progress = islenenDosyaSayisi / toplamDosyaSayisi * 100; ilerlemeCallback(progress); } catch (e) { print('Dosya eklenirken hata oluştu: ${file.path} - $e'); } } } } } // ZIP dosyasını yaz File zipFile = File(zipDosyasiYolu); await zipFile.writeAsBytes(ZipEncoder().encode(archive, autoClose: true, level: Deflate.NO_COMPRESSION) ?? []); print('Yedekleme ve zipleme tamamlandı: $zipDosyasiYolu'); } catch (e) { print('Hata oluştu: $e'); } } Future zipCikart({ required String zipDosyasiYolu, required String hedefDizin, required Function(double) ilerlemeCallback, }) async { try { // ZIP dosyasını oku File zipFile = File(zipDosyasiYolu); if (!await zipFile.exists()) { throw Exception('ZIP dosyası bulunamadı: $zipDosyasiYolu'); } List zipBytes = await zipFile.readAsBytes(); // ZIP içeriğini çöz Archive archive = ZipDecoder().decodeBytes(zipBytes); int toplamDosyaSayisi = archive.files.length; int islenenDosyaSayisi = 0; // Hedef dizini oluştur (varsa zaten oluşturmaz) Directory hedefDir = Directory(hedefDizin); if (!await hedefDir.exists()) { await hedefDir.create(recursive: true); } for (ArchiveFile file in archive.files) { if (file.isFile) { // Dosyanın yolunu oluştur String filePath = '$hedefDizin/${file.name}'.replaceAll('\\', '/'); // Var olan dosya varsa sil File outFile = File(filePath); if (await outFile.exists()) { await outFile.delete(); } // Dosyayı yaz await outFile.create(recursive: true); await outFile.writeAsBytes(file.content as List); // İlerleme durumunu güncelle islenenDosyaSayisi++; double progress = islenenDosyaSayisi / toplamDosyaSayisi * 100; ilerlemeCallback(progress); } } print('ZIP çıkartma tamamlandı: $hedefDizin'); } catch (e) { print('Hata oluştu: $e'); } } Future yedekle({required String zipDosyasiYolu, required Function(double) ilerlemeCallback}) async { Directory dirDatabase = Directory(await FikoYTService.programYolu(ekYol: "databases")); Directory dirMedyalar = Directory(await FikoYTService.programYolu(ekYol: "medya_hareketler")); Directory dirResimler = Directory(await FikoYTService.programYolu(ekYol: "resimler")); List dizinler = []; if (await dirDatabase.exists()) dizinler.add(dirDatabase.path); if (await dirMedyalar.exists()) dizinler.add(dirMedyalar.path); if (await dirResimler.exists()) dizinler.add(dirResimler.path); await yedekleVeZiple(dizinler: dizinler, zipDosyasiYolu: zipDosyasiYolu, ilerlemeCallback: ilerlemeCallback); } Future yedekYukle({required String zipDosyasiYolu, required Function(double) ilerlemeCallback}) async { await zipCikart(hedefDizin: await FikoYTService.programYolu(), zipDosyasiYolu: zipDosyasiYolu, ilerlemeCallback: ilerlemeCallback); } } class PageMesaiciYedekleme extends StatefulWidget { const PageMesaiciYedekleme({super.key}); @override _PageMesaiciYedeklemeState createState() => _PageMesaiciYedeklemeState(); } // enum YedeklemePeriyot { GUNLUK, HAFTALIK, AYLIK, YOK } class _PageMesaiciYedeklemeState extends State { PageMesaiciYedeklemeLogic logic = Get.put(PageMesaiciYedeklemeLogic()); BasePageLogic basePageLogic = Get.put(BasePageLogic()); //---> // final GlobalKey globalKeysAktifGun = GlobalKey(); // final scrollController = ScrollController(); //---> // YedeklemePeriyot? _yedeklemePeriyot = YedeklemePeriyot.GUNLUK; @override void initState() { super.initState(); // WidgetsBinding.instance.addPostFrameCallback((_) async { // await Future.delayed(const Duration(milliseconds: 1000)); // RenderObject? aktifAyObject = globalKeysAktifGun.currentContext?.findRenderObject(); // // print(globalKeysAktifAy); // if (aktifAyObject != null) { // basePageLogic.scrollController.position.ensureVisible( // aktifAyObject, // alignment: 0.1, // How far into view the item should be scrolled (between 0 and 1). // duration: const Duration(seconds: 1), // ); // } // }); } @override void dispose() { Get.delete(); // scrollController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { SchedulerBinding.instance.addPostFrameCallback((_) { basePageLogic.subTitle.value = "🗄️ Hareketler"; // print(context.vRouter.pathParameters["ay"]); }); ScreenSizeTypes screenType = FikoYTElastic.getScreenSizeType(context); [ // ScreenSizeTypes.small, ScreenSizeTypes.mini, ScreenSizeTypes.extraMini ].contains(screenType); return FikoYTSliverApp( scrollController: basePageLogic.scrollController, leading: const UygulamaBaslikSol(), title: UygulamaBaslikOrta(), actions: const [ UygulamaBaslikSag(), ], headerWidget: Visibility( visible: FikoYTService.servisMesaici.vtHatasi.value == false, child: PageView( children: [ Container( color: Colors.transparent, //Colors.orange, height: 300 - kToolbarHeight - 10, margin: const EdgeInsets.only(top: kToolbarHeight, bottom: 10, right: 10, left: 10), child: KullaniciBilgiNavigasyon( simge: const Text( "📱", style: TextStyle( fontSize: 54, ), ), ), ), ], ), ), bodyColor: Colors.transparent, body: [ Visibility( visible: FikoYTService.servisMesaici.vtHatasi.value == false, child: Column( children: [ const Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( child: Divider( indent: 20.0, endIndent: 10.0, thickness: 1, ), ), Text( "Yedekleme Periyodu", style: TextStyle(color: Colors.blueGrey, fontSize: 14), ), Expanded( child: Divider( indent: 10.0, endIndent: 20.0, thickness: 1, ), ), ], ), ListTile( title: const Text('Yok'), leading: Radio( value: YedeklemePeriyot.YOK, groupValue: FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot, onChanged: (YedeklemePeriyot? value) { setState(() { FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot = value!; FikoYTService.servisMesaici.ayarlarModel?.refresh(); }); }, ), onTap: () { setState(() { FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot = YedeklemePeriyot.YOK; FikoYTService.servisMesaici.ayarlarModel?.refresh(); }); }, ), ListTile( title: const Text('Günlük'), leading: Radio( value: YedeklemePeriyot.GUNLUK, groupValue: FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot, onChanged: (YedeklemePeriyot? value) { setState(() { FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot = value!; FikoYTService.servisMesaici.ayarlarModel?.refresh(); }); }, ), onTap: () { setState(() { FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot = YedeklemePeriyot.GUNLUK; FikoYTService.servisMesaici.ayarlarModel?.refresh(); }); }, ), ListTile( title: const Text('Haftalık'), leading: Radio( value: YedeklemePeriyot.HAFTALIK, groupValue: FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot, onChanged: (YedeklemePeriyot? value) { setState(() { FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot = value!; FikoYTService.servisMesaici.ayarlarModel?.refresh(); }); }, ), onTap: () { setState(() { FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot = YedeklemePeriyot.HAFTALIK; FikoYTService.servisMesaici.ayarlarModel?.refresh(); }); }, ), ListTile( title: const Text('Aylık'), leading: Radio( value: YedeklemePeriyot.AYLIK, groupValue: FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot, onChanged: (YedeklemePeriyot? value) { setState(() { FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot = value!; FikoYTService.servisMesaici.ayarlarModel?.refresh(); }); }, ), onTap: () { setState(() { FikoYTService.servisMesaici.ayarlarModel?.value.yedeklemePeriyot = YedeklemePeriyot.AYLIK; FikoYTService.servisMesaici.ayarlarModel?.refresh(); }); }, ), ], ), ), Visibility( visible: FikoYTService.servisMesaici.vtHatasi.value == true, child: Padding( padding: const EdgeInsets.all(5), child: FikoYTButton( text: "Veritabanında Bir Hata Tespit Edildi. Eğer Daha Önceden Yedeğiniz Var İse Bu Yedeklerden Geri Yükleme Yapabilirsiniz.Yok İse Sıfırla Butonuna Basınız.", tema: Theme.of(context).extension()?.copyWith( textColor: Colors.red, textStrokeColor: Colors.transparent, ), ), ), ), /** */ // Visibility( // visible: FikoYTService.servisMesaici.vtHatasi.value == false, // child: Padding( // padding: const EdgeInsets.all(5), // child: FikoYTButton( // text: Obx( // () => AnimatedCrossFade( // firstChild: const Row( // crossAxisAlignment: CrossAxisAlignment.center, // mainAxisAlignment: MainAxisAlignment.center, // children: [ // Text( // "🗃️ Şimdi Yedekle", // style: TextStyle( // color: Colors.black, // fontSize: 12, // ), // ), // ], // ), // secondChild: Row( // crossAxisAlignment: CrossAxisAlignment.center, // mainAxisAlignment: MainAxisAlignment.center, // children: [ // Container( // width: 18, // height: 18, // padding: const EdgeInsets.all(4.0), // child: const CircularProgressIndicator( // color: Colors.blue, // strokeWidth: 3, // ), // ), // ], // ), // crossFadeState: logic.simdiYedekleniyor.value ? CrossFadeState.showSecond : CrossFadeState.showFirst, // duration: const Duration(milliseconds: 500), // ), // ), // tema: Theme.of(context).extension()?.copyWith( // fontSize: 11, // radius: 20, // edgePadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), // backgroundColor: Colors.white, // textColor: Colors.green, // textStrokeColor: Colors.transparent, // borderColor: Colors.blue, // ), // onPressed: () async { // if (logic.simdiYedekleniyor.isTrue) return; // logic.simdiYedekleniyor.value = true; // logic.simdiYedekleniyor.refresh(); // try { // FikoYTService.servisMesaici.isar?.copyToFile('${await FikoYTService.programYolu(ekYol: 'yedekler')}${DateTime.now().formatla('dd_MM_yyyy HH_mm_ss')}.FikoYedek'); // SnackBar snck = const SnackBar( // content: Text('Dosya Kaydedildi'), // duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi // ); // ScaffoldMessenger.of(context).showSnackBar(snck); // } catch (e) { // print(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); // } finally { // await Future.delayed(const Duration(milliseconds: 1000)); // logic.simdiYedekleniyor.value = false; // logic.simdiYedekleniyor.refresh(); // FikoYTService.servisMesaici.aktifCalisma?.refresh(); // FikoYTService.servisMesaici.ayarlarModel?.refresh(); // } // // FikoYTService.servisMesaici.isar.copyToFile('${await FikoYTService.programYolu()}selam.db'); // // FikoYTService.servisMesaici.isar.copyToFile('${await FikoYTService.programYolu(ekYol: 'yedekler')}${DateTime.now().formatla('dd_MM_yyyy HH_mm_ss')}.FikoYedek'); // // print(DateTime.now()); // }, // ), // ), // /** */ // ), Visibility( visible: FikoYTService.servisMesaici.vtHatasi.value == false, child: Padding( padding: const EdgeInsets.all(5), child: FikoYTButton( text: Obx( () => AnimatedCrossFade( firstChild: const Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "🗃️ Şimdi Yedekle Zip", style: TextStyle( color: Colors.black, fontSize: 12, ), ), ], ), secondChild: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 18, height: 18, padding: const EdgeInsets.all(4.0), child: const CircularProgressIndicator( color: Colors.blue, strokeWidth: 3, ), ), ], ), crossFadeState: logic.simdiYedekleniyor.value ? CrossFadeState.showSecond : CrossFadeState.showFirst, duration: const Duration(milliseconds: 500), ), ), tema: Theme.of(context).extension()?.copyWith( fontSize: 11, radius: 20, edgePadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), backgroundColor: Colors.white, textColor: Colors.green, textStrokeColor: Colors.transparent, borderColor: Colors.blue, ), onPressed: () async { if (logic.simdiYedekleniyor.isTrue) return; logic.simdiYedekleniyor.value = true; logic.simdiYedekleniyor.refresh(); try { await logic.yedekle( zipDosyasiYolu: '${await FikoYTService.programYolu(ekYol: 'yedekler')}${DateTime.now().formatla('dd_MM_yyyy HH_mm_ss')}.FikoYedek', ilerlemeCallback: (v) { print(v); }); //FikoYTService.servisMesaici.isar?.copyToFile('${await FikoYTService.programYolu(ekYol: 'yedekler')}${DateTime.now().formatla('dd_MM_yyyy HH_mm_ss')}.FikoYedek'); SnackBar snck = const SnackBar( content: Text('Dosya Kaydedildi'), duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ); ScaffoldMessenger.of(context).showSnackBar(snck); } catch (e) { print(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); } finally { await Future.delayed(const Duration(milliseconds: 1000)); logic.simdiYedekleniyor.value = false; logic.simdiYedekleniyor.refresh(); FikoYTService.servisMesaici.aktifCalisma?.refresh(); FikoYTService.servisMesaici.ayarlarModel?.refresh(); } }, ), ), /** */ ), /** */ Padding( padding: const EdgeInsets.all(5), child: FikoYTButton( text: Obx( () => AnimatedCrossFade( firstChild: const Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( "📁 Dosyadan Yükle", style: TextStyle( color: Colors.black, fontSize: 12, ), ), ], ), secondChild: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 18, height: 18, padding: const EdgeInsets.all(4.0), child: const CircularProgressIndicator( color: Colors.blue, strokeWidth: 3, ), ), ], ), crossFadeState: logic.dosyadanYukleniyor.value ? CrossFadeState.showSecond : CrossFadeState.showFirst, duration: const Duration(milliseconds: 500), ), ), tema: Theme.of(context).extension()?.copyWith( fontSize: 11, radius: 20, edgePadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), backgroundColor: Colors.white, textColor: Colors.green, textStrokeColor: Colors.transparent, borderColor: Colors.blue, ), onPressed: () async { if (logic.dosyadanYukleniyor.isTrue) return; logic.dosyadanYukleniyor.value = true; logic.dosyadanYukleniyor.refresh(); try { // Dosya seçme FilePickerResult? result = await FilePicker.platform.pickFiles( dialogTitle: 'Kayıt dosyasını seçin', type: FileType.any, // 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!; if (filePath.endsWith(".FikoYedek") == false) { SnackBar snck = const SnackBar( content: Text('Dosya Bu Programı Desteklemiyor'), backgroundColor: Colors.red, duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ); ScaffoldMessenger.of(context).showSnackBar(snck); return; } // Dosyanın içeriğini oku /** */ if (!Platform.isWindows) FikoYTService.servisMesaici.arkaPlanServis.invoke("mesaici.servis.durdur"); await FikoYTService.servisMesaici.isar?.close(); await FikoYTService.servisMesaici.profilResmiSil(); // File file = File(filePath); // await file.copy('${await FikoYTService.programYolu(ekYol: 'databases')}FikoYT.db.isar'); await logic.yedekYukle( zipDosyasiYolu: filePath, ilerlemeCallback: (p0) { print("Dosyadan Yedek Yükleniyor "); }, ); await FikoYTService.servisMesaici.isar_init(); await FikoYTService.servisMesaici.ayarlar_init(); await FikoYTService.servisMesaici.aktifCalisma_init(); if (!Platform.isWindows) await FikoYTService.servisMesaici.arkaPlanServisInit(); if ((await FikoYTService.servisMesaici.profilResmiAl).existsSync()) { FikoYTService.servisMesaici.profilResmi.value = (await FikoYTService.servisMesaici.profilResmiAl).readAsBytesSync(); } else { await FikoYTService.servisMesaici.profilResmiSil(); } SnackBar snck = const SnackBar( content: Text('Yedek Yüklendi'), duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ); ScaffoldMessenger.of(context).showSnackBar(snck); if (FikoYTService.servisMesaici.vtHatasi.value == false) { await Future.delayed(const Duration(milliseconds: 1000)); // await Restart.restartApp(); FikoYTCoreService.parlaklik.refresh(); // context.vRouter.to("/mesaici"); } } else {} } catch (e) { print(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); } finally { await Future.delayed(const Duration(milliseconds: 1000)); logic.dosyadanYukleniyor.value = false; logic.dosyadanYukleniyor.refresh(); FikoYTService.servisMesaici.ayarlarModel?.refresh(); FikoYTService.servisMesaici.aktifCalisma?.refresh(); } }, ), /** */ ), /** */ Visibility( visible: FikoYTService.servisMesaici.vtHatasi.value == false, child: Padding( padding: const EdgeInsets.all(5), child: FikoYTButton( text: "Yedekleri Geri Yüklemeden Önce Mevcut Verilerinizi Kaybetmemeniz İçin Yeni Yedek Almanızı Tavsiye Ederiz.", tema: Theme.of(context).extension()?.copyWith( textColor: Colors.deepOrange, textStrokeColor: Colors.transparent, fontWeight: FontWeight.normal, ), ), ), ), /** */ Row( mainAxisAlignment: MainAxisAlignment.center, children: [ const Expanded( child: Divider( indent: 0.0, endIndent: 10.0, thickness: 1, ), ), const Text( "📦 Alınan Yedekler", style: TextStyle(color: Colors.blueGrey, fontSize: 14), ), const Expanded( child: Divider( indent: 10.0, endIndent: 0.0, thickness: 1, ), ), FikoYTButton( text: "♻️", onPressed: () async { // Directory yedekKlasoru = Directory(await FikoYTService.programYolu(ekYol: 'yedekler')); // print(yedekKlasoru.listSync()); FikoYTService.servisMesaici.aktifCalisma?.refresh(); }, ), const SizedBox( width: 10, ) ], ), /** */ Obx( () { FikoYTService.servisMesaici.aktifCalisma?.value; return FutureBuilder( future: Future.sync( () async { return Directory(await FikoYTService.programYolu(ekYol: 'yedekler')).listSync().toList()..sort((l, r) => r.statSync().modified.compareTo(l.statSync().modified)); }, ), builder: (context, snapshot) { if (snapshot.hasData) { final dosyalar = snapshot.data; // if (todos!.isNotEmpty) { return AnimatedSwitcher( duration: const Duration(milliseconds: 750), transitionBuilder: (Widget child, Animation animation) { return FadeTransition( opacity: animation, child: SizeTransition( sizeFactor: animation, axisAlignment: 2, // fixedCrossAxisSizeFactor: 1, axis: Axis.vertical, child: child, ), ); }, child: AnimatedCrossFade( key: const ValueKey("Dosyalar"), duration: const Duration(milliseconds: 300), crossFadeState: dosyalar!.isNotEmpty ? CrossFadeState.showFirst : CrossFadeState.showSecond, firstChild: ListView.separated( padding: const EdgeInsets.symmetric(vertical: 10.0), physics: const BouncingScrollPhysics(), shrinkWrap: true, itemCount: dosyalar.length, separatorBuilder: (context, index) => const SizedBox( height: 5, ), itemBuilder: (context, index) { final dosya = dosyalar[index]; return Dismissible( direction: DismissDirection.horizontal, // this will only allow slide to left. dismissThresholds: const {DismissDirection.endToStart: 0.4, DismissDirection.startToEnd: 0.4}, key: ValueKey(dosya.statSync().modified.formatla("dd.MM.yyyy HH:mm:ss EEEE")), background: Row( children: [ FikoYTButton( text: const Icon( Icons.upload, color: Colors.red, size: 14, ), ), const Spacer(), FikoYTButton( text: const Icon( Icons.delete, color: Colors.red, size: 14, ), ), ], ), confirmDismiss: (direction) async { if (direction == DismissDirection.endToStart) { return true; } else { await FikoYTService.servisMesaici.isar?.close(); File file = File(dosya.absolute.path); String? outputPath = await FilePicker.platform.saveFile( dialogTitle: 'Kayıt dosyası nereye kaydedilsin?', fileName: '${DateTime.now().formatla('dd_MM_yyyy HH_mm_ss')}.FikoYedek', bytes: Uint8List.fromList([]), //file.readAsBytesSync(), ); await FikoYTService.servisMesaici.isar_init(); await FikoYTService.servisMesaici.ayarlar_init(); await FikoYTService.servisMesaici.aktifCalisma_init(); await FikoYTService.servisMesaici.arkaPlanServisInit(); if (outputPath != null) { File outputFile = File(outputPath); // Dosyayı akışla kaydet outputFile.openWrite() ..addStream(fileStream) ..close(); SnackBar snck = const SnackBar( content: Text('Yedek Dışarı Aktarıldı'), backgroundColor: Colors.red, duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ); ScaffoldMessenger.of(context).showSnackBar(snck); } return false; } }, onDismissed: (DismissDirection direction) async { if (direction == DismissDirection.endToStart) { dosyalar.removeAt(index); await dosya.delete(); FikoYTService.servisMesaici.aktifCalisma?.refresh(); } else if (direction == DismissDirection.startToEnd) {} }, child: FikoYTButton( text: Obx( () => AnimatedCrossFade( firstChild: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.start, children: [ const Text("📅"), Text( // key: DateTime.now().formatla("dd.MM.yyyy EEEE") == gun.tarih!.formatla("dd.MM.yyyy EEEE") ? globalKeysAktifGun : null, dosya.statSync().modified.formatla("dd.MM.yyyy HH:mm:ss EEEE"), ), ], ), secondChild: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 18, height: 18, padding: const EdgeInsets.all(4.0), child: const CircularProgressIndicator( color: Colors.blue, strokeWidth: 3, ), ), ], ), crossFadeState: logic.yuklenenItem.value == dosya.statSync().modified.formatla("dd.MM.yyyy HH:mm:ss EEEE") ? CrossFadeState.showSecond : CrossFadeState.showFirst, duration: const Duration(milliseconds: 500), ), ), onPressed: () async { if (logic.yuklenenItem.value == dosya.statSync().modified.formatla("dd.MM.yyyy HH:mm:ss EEEE")) return; logic.yuklenenItem.value = dosya.statSync().modified.formatla("dd.MM.yyyy HH:mm:ss EEEE"); logic.yuklenenItem.refresh(); try { String filePath = dosya.absolute.path; // Dosyanın içeriğini oku /** */ if (!Platform.isWindows) FikoYTService.servisMesaici.arkaPlanServis.invoke("mesaici.servis.durdur"); await FikoYTService.servisMesaici.isar?.close(); await FikoYTService.servisMesaici.profilResmiSil(); File file = File(filePath); // await file.copy('${await FikoYTService.programYolu(ekYol: 'databases')}FikoYT.db.isar'); await logic.yedekYukle( zipDosyasiYolu: filePath, ilerlemeCallback: (p0) { print("Yedek Yükleniyor "); }, ); await FikoYTService.servisMesaici.isar_init(); await FikoYTService.servisMesaici.ayarlar_init(); await FikoYTService.servisMesaici.aktifCalisma_init(); // if (!Platform.isWindows) await FikoYTService.servisMesaici.arkaPlanServisInit(); if ((await FikoYTService.servisMesaici.profilResmiAl).existsSync()) { FikoYTService.servisMesaici.profilResmi.value = (await FikoYTService.servisMesaici.profilResmiAl).readAsBytesSync(); } else { await FikoYTService.servisMesaici.profilResmiSil(); } SnackBar snck = const SnackBar( content: Text('Yedek Yüklendi'), duration: Duration(seconds: 2), // SnackBar'ın ekranda kalma süresi ); ScaffoldMessenger.of(context).showSnackBar(snck); if (FikoYTService.servisMesaici.vtHatasi.value == false) { await Future.delayed(const Duration(milliseconds: 1000)); // await Restart.restartApp(); FikoYTCoreService.parlaklik.refresh(); // context.vRouter.to("/mesaici"); } } catch (e) { print(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); } finally { await Future.delayed(const Duration(milliseconds: 1000)); logic.yuklenenItem.value = ""; logic.yuklenenItem.refresh(); FikoYTService.servisMesaici.aktifCalisma?.refresh(); } }, tema: Theme.of(context).extension()?.copyWith( backgroundColor: Colors.white, borderColor: Colors.black12, edgePadding: const EdgeInsets.symmetric(vertical: 2, horizontal: 5), ), ), ); }, ), secondChild: 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: 24), ), ), ), ), Padding( padding: const EdgeInsets.only(top: 48), child: Align( alignment: const FractionalOffset(0.5, 0.5), child: Text( "Herhangi Bir Yedek Kaydınız Bulunamadı", style: TextStyle(fontSize: 16, fontWeight: FontWeight.w300, color: Colors.blueAccent.shade400), textAlign: TextAlign.center, ), ), ), ], ), ), ), ); } return const CircularProgressIndicator(); }, ); }, ), ], headerExpandedHeight: 315, // stretchMaxHeight: 100, fullyStretchable: false, backgroundColor: Theme.of(context).extension()?.backgroundColor, //Colors.grey.shade200, centerTitle: true, alwaysShowLeadingAndAction: true, appBarColor: Colors.blue.shade500, alwaysShowTitle: true, curvedBodyRadius: 0, onStretchTrigger: () async { context.vRouter.to("/"); }, ); } }