import 'dart:ui'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_acrylic/flutter_acrylic.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:video_player_win/video_player_win_plugin.dart'; import 'package:window_manager/window_manager.dart'; import 'app.dart'; import 'servisler/job_orkestratoru.dart'; /// Son yakalanan ölümcül hata (UI boş kalırsa overlay'de gösterilir) final ValueNotifier sonHataDetay = ValueNotifier(null); Future main() async { WidgetsFlutterBinding.ensureInitialized(); // Tüm Flutter ve async hatalarını yakala — siyah ekran/sessiz çökme yerine // gerçek hatayı ekrana bastır. FlutterError.onError = (details) { FlutterError.presentError(details); sonHataDetay.value = details; }; PlatformDispatcher.instance.onError = (error, stack) { debugPrint('PlatformDispatcher hatası: $error\n$stack'); sonHataDetay.value = FlutterErrorDetails( exception: error, stack: stack, library: 'PlatformDispatcher', ); return true; }; // ErrorWidget yerine kendimizinki — render hatası olduğunda kırmızı yama // değil okunaklı bir mesaj göster. ErrorWidget.builder = (details) { sonHataDetay.value = details; return Material( color: const Color(0xFF1a0000), child: Padding( padding: const EdgeInsets.all(24), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( 'Widget render hatası', style: TextStyle( color: Colors.redAccent, fontSize: 18, fontWeight: FontWeight.bold), ), const SizedBox(height: 12), Expanded( child: SingleChildScrollView( child: SelectableText( '${details.exception}\n\n${details.stack}', style: const TextStyle( color: Colors.white70, fontFamily: 'monospace', fontSize: 11), ), ), ), ], ), ), ); }; String? baslatmaHatasi; try { await Hive.initFlutter(); } catch (e, st) { baslatmaHatasi = 'Hive init: $e\n$st'; debugPrint(baslatmaHatasi); } try { await Window.initialize(); await windowManager.ensureInitialized(); WindowsVideoPlayer.registerWith(); await windowManager.waitUntilReadyToShow( const WindowOptions( size: Size(1480, 920), minimumSize: Size(1100, 720), center: true, backgroundColor: Colors.transparent, titleBarStyle: TitleBarStyle.normal, title: 'FikoYT Video Stüdyo', ), () async { try { await Window.setEffect(effect: WindowEffect.acrylic, dark: true); } catch (_) {} await windowManager.show(); await windowManager.focus(); }, ); } catch (e, st) { baslatmaHatasi ??= 'Pencere init: $e\n$st'; debugPrint('Pencere init: $e\n$st'); } try { await JobOrkestratoru.ornek.baslat(); } catch (e, st) { baslatmaHatasi ??= 'Job orchestrator: $e\n$st'; debugPrint('Job orchestrator hatası: $e\n$st'); } // Render pipeline'ın test ekranı (sadece başlatma hatası varsa görünür) if (baslatmaHatasi != null) { runApp(MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( backgroundColor: Colors.green, body: Padding( padding: const EdgeInsets.all(40), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( 'FİKOYT TEST EKRANI', style: TextStyle( color: Colors.white, fontSize: 32, fontWeight: FontWeight.bold), ), const SizedBox(height: 16), if (baslatmaHatasi != null) Text(baslatmaHatasi, style: const TextStyle(color: Colors.white, fontSize: 14)) else const Text( 'Bu yeşil ekranı görüyorsan render OK.\nVideoStudyoApp/Router/Tema kısmında sorun var.', style: TextStyle(color: Colors.white, fontSize: 16)), ], ), ), ), )); return; } runApp(const ProviderScope(child: VideoStudyoApp())); } class _BaslatmaHataEkrani extends StatelessWidget { final String mesaj; const _BaslatmaHataEkrani({required this.mesaj}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( backgroundColor: const Color(0xFF0F1115), body: Padding( padding: const EdgeInsets.all(24), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( 'Başlatma hatası', style: TextStyle( color: Colors.redAccent, fontSize: 20, fontWeight: FontWeight.bold), ), const SizedBox(height: 12), Expanded( child: SingleChildScrollView( child: SelectableText( mesaj, style: const TextStyle( color: Colors.white70, fontFamily: 'monospace', fontSize: 12), ), ), ), ], ), ), ), ); } }