import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; // Para as orientações import 'package:supabase_flutter/supabase_flutter.dart'; import 'package:playmaker/classe/theme.dart'; import 'pages/login.dart'; import 'utils/session_manager.dart'; // Variável global para controlar o Tema final ValueNotifier themeNotifier = ValueNotifier(ThemeMode.system); void main() async { // 1. Inicializa os bindings do Flutter WidgetsFlutterBinding.ensureInitialized(); // 2. Inicializa o Supabase await Supabase.initialize( url: 'https://sihwjdshexjyvsbettcd.supabase.co', anonKey: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNpaHdqZHNoZXhqeXZzYmV0dGNkIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njg5MTQxMjgsImV4cCI6MjA4NDQ5MDEyOH0.gW3AvTJVNyE1Dqa72OTnhrUIKsndexrY3pKxMIAaAy8', ); // 3. Deixa a orientação livre (Portrait) para o arranque da App SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, ]); runApp(const MyApp()); } class MyApp extends StatefulWidget { const MyApp({super.key}); @override State createState() => _MyAppState(); } class _MyAppState extends State with WidgetsBindingObserver { @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); } @override void dispose() { WidgetsBinding.instance.removeObserver(this); super.dispose(); } @override void didChangeAppLifecycleState(AppLifecycleState state) async { super.didChangeAppLifecycleState(state); // Quando a app for para background/terminar, se houver sessão em progresso, desliga a sessão if (state == AppLifecycleState.paused || state == AppLifecycleState.detached) { final inProgress = await SessionManager.isInProgress(); if (inProgress) { try { await Supabase.instance.client.auth.signOut(); await SessionManager.clear(); } catch (_) {} } } } @override Widget build(BuildContext context) { return ValueListenableBuilder( valueListenable: themeNotifier, builder: (_, ThemeMode currentMode, __) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'PlayMaker', theme: AppTheme.lightTheme, darkTheme: AppTheme.darkTheme, themeMode: currentMode, home: const LoginPage(), ); }, ); } }