80 lines
2.4 KiB
Dart
80 lines
2.4 KiB
Dart
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<ThemeMode> 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<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> 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<ThemeMode>(
|
|
valueListenable: themeNotifier,
|
|
builder: (_, ThemeMode currentMode, __) {
|
|
return MaterialApp(
|
|
debugShowCheckedModeBanner: false,
|
|
title: 'PlayMaker',
|
|
theme: AppTheme.lightTheme,
|
|
darkTheme: AppTheme.darkTheme,
|
|
themeMode: currentMode,
|
|
home: const LoginPage(),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
} |