Videos na nuvem | atualização de desing (Appbar) | mudança no quiz

This commit is contained in:
Carlos Correia
2026-07-08 22:23:38 +01:00
parent a7b6d35026
commit 67b580778a
12 changed files with 885 additions and 660 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
@@ -7,9 +9,53 @@ import 'logged_home.dart';
final ValueNotifier<bool> forceHomeScreen = ValueNotifier<bool>(false);
class AuthGate extends StatelessWidget {
class AuthGate extends StatefulWidget {
const AuthGate({super.key});
@override
State<AuthGate> createState() => _AuthGateState();
}
class _AuthGateState extends State<AuthGate> {
String? _validatedUserId;
String? _validatingUserId;
/// Confirma que a sessão ativa ainda corresponde a um perfil existente na
/// base de dados. Sessões do Supabase Auth sobrevivem mesmo que os dados
/// da conta tenham sido apagados (ex.: "Apagar dados da conta" ou remoção
/// manual na base de dados) — sem esta verificação, essa conta "fantasma"
/// continuaria a conseguir entrar.
Future<void> _validateSession(String userId) async {
if (_validatingUserId == userId) return;
_validatingUserId = userId;
try {
final profile = await supabase
.from('profiles')
.select('id')
.eq('id', userId)
.maybeSingle();
if (!mounted) return;
if (profile == null) {
unawaited(
supabase
.from('children')
.delete()
.eq('owner_id', userId)
.catchError((_) => <Map<String, dynamic>>[]),
);
await supabase.auth.signOut();
} else {
setState(() => _validatedUserId = userId);
}
} catch (_) {
// Falha de rede/consulta: não força logout, tenta novamente depois.
} finally {
_validatingUserId = null;
}
}
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<bool>(
@@ -21,10 +67,16 @@ class AuthGate extends StatelessWidget {
builder: (context, snapshot) {
final user = snapshot.data?.session?.user;
if (user != null && user.id != _validatedUserId) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _validateSession(user.id);
});
}
final Widget child;
if (snapshot.connectionState == ConnectionState.waiting) {
child = const SizedBox.shrink();
} else if (forcedHome || user == null) {
} else if (forcedHome || user == null || user.id != _validatedUserId) {
child = const HomeScreen(key: ValueKey('home_screen'));
} else {
child = const LoggedHomeScreen(key: ValueKey('logged_home_screen'));