Videos na nuvem | atualização de desing (Appbar) | mudança no quiz
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
|
|
||||||
@@ -7,9 +9,53 @@ import 'logged_home.dart';
|
|||||||
|
|
||||||
final ValueNotifier<bool> forceHomeScreen = ValueNotifier<bool>(false);
|
final ValueNotifier<bool> forceHomeScreen = ValueNotifier<bool>(false);
|
||||||
|
|
||||||
class AuthGate extends StatelessWidget {
|
class AuthGate extends StatefulWidget {
|
||||||
const AuthGate({super.key});
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ValueListenableBuilder<bool>(
|
return ValueListenableBuilder<bool>(
|
||||||
@@ -21,10 +67,16 @@ class AuthGate extends StatelessWidget {
|
|||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
final user = snapshot.data?.session?.user;
|
final user = snapshot.data?.session?.user;
|
||||||
|
|
||||||
|
if (user != null && user.id != _validatedUserId) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
if (mounted) _validateSession(user.id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
child = const SizedBox.shrink();
|
child = const SizedBox.shrink();
|
||||||
} else if (forcedHome || user == null) {
|
} else if (forcedHome || user == null || user.id != _validatedUserId) {
|
||||||
child = const HomeScreen(key: ValueKey('home_screen'));
|
child = const HomeScreen(key: ValueKey('home_screen'));
|
||||||
} else {
|
} else {
|
||||||
child = const LoggedHomeScreen(key: ValueKey('logged_home_screen'));
|
child = const LoggedHomeScreen(key: ValueKey('logged_home_screen'));
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:lottie/lottie.dart';
|
|||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
|
|
||||||
import 'main.dart' show supabase;
|
import 'main.dart' show supabase;
|
||||||
|
import 'widgets/app_gradients.dart';
|
||||||
import 'widgets/entrance.dart';
|
import 'widgets/entrance.dart';
|
||||||
import 'widgets/tap_bounce.dart';
|
import 'widgets/tap_bounce.dart';
|
||||||
|
|
||||||
@@ -15,6 +16,12 @@ const Color _pink = Color(0xFFFF55A7);
|
|||||||
/// Nomes só podem ter letras (incluindo acentuadas) e espaços — sem números.
|
/// Nomes só podem ter letras (incluindo acentuadas) e espaços — sem números.
|
||||||
final RegExp _namePattern = RegExp(r"^[a-zA-ZÀ-ÖØ-öø-ÿ' -]+$");
|
final RegExp _namePattern = RegExp(r"^[a-zA-ZÀ-ÖØ-öø-ÿ' -]+$");
|
||||||
|
|
||||||
|
/// A conta existe no Supabase Auth mas os dados (perfil) já não existem na
|
||||||
|
/// base de dados — tratada como conta inexistente para efeitos de login.
|
||||||
|
class _AccountNotFoundException implements Exception {
|
||||||
|
const _AccountNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
class HomeScreen extends StatefulWidget {
|
class HomeScreen extends StatefulWidget {
|
||||||
const HomeScreen({super.key});
|
const HomeScreen({super.key});
|
||||||
|
|
||||||
@@ -50,11 +57,10 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
required String name,
|
required String name,
|
||||||
required String email,
|
required String email,
|
||||||
}) async {
|
}) async {
|
||||||
await supabase.from('profiles').upsert({
|
await supabase
|
||||||
'id': uid,
|
.from('profiles')
|
||||||
'name': name,
|
.upsert({'id': uid, 'name': name, 'email': email})
|
||||||
'email': email,
|
.timeout(const Duration(seconds: 20));
|
||||||
}).timeout(const Duration(seconds: 20));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _submit() async {
|
Future<void> _submit() async {
|
||||||
@@ -66,10 +72,34 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
final password = _passwordController.text;
|
final password = _passwordController.text;
|
||||||
|
|
||||||
if (_isLogin) {
|
if (_isLogin) {
|
||||||
await supabase.auth.signInWithPassword(
|
final result = await supabase.auth.signInWithPassword(
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final user = result.user;
|
||||||
|
if (user != null) {
|
||||||
|
final profile = await supabase
|
||||||
|
.from('profiles')
|
||||||
|
.select('id')
|
||||||
|
.eq('id', user.id)
|
||||||
|
.maybeSingle();
|
||||||
|
|
||||||
|
if (profile == null) {
|
||||||
|
// A conta existe no Auth mas os dados foram apagados (ex.: via
|
||||||
|
// "Apagar dados da conta" ou diretamente na base de dados).
|
||||||
|
// Trata como inexistente: limpa qualquer resquício e bloqueia.
|
||||||
|
unawaited(
|
||||||
|
supabase
|
||||||
|
.from('children')
|
||||||
|
.delete()
|
||||||
|
.eq('owner_id', user.id)
|
||||||
|
.catchError((_) => <Map<String, dynamic>>[]),
|
||||||
|
);
|
||||||
|
await supabase.auth.signOut();
|
||||||
|
throw const _AccountNotFoundException();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
final name = _nameController.text.trim();
|
final name = _nameController.text.trim();
|
||||||
final response = await supabase.auth
|
final response = await supabase.auth
|
||||||
@@ -81,14 +111,19 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
throw StateError('Usuário não encontrado após criar conta.');
|
throw StateError('Usuário não encontrado após criar conta.');
|
||||||
}
|
}
|
||||||
|
|
||||||
unawaited(
|
// Precisa de terminar antes de navegar: o AuthGate só mostra a app
|
||||||
_persistRegistrationData(
|
// depois de confirmar que existe um perfil na base de dados.
|
||||||
uid: user.id,
|
await _persistRegistrationData(uid: user.id, name: name, email: email);
|
||||||
name: name,
|
|
||||||
email: email,
|
|
||||||
).catchError((_) {}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
} on _AccountNotFoundException {
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'Esta conta não existe mais. Verifique o email ou crie uma nova conta.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
} on AuthException catch (e) {
|
} on AuthException catch (e) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
ScaffoldMessenger.of(
|
ScaffoldMessenger.of(
|
||||||
@@ -412,12 +447,16 @@ class _AuthForm extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
TapBounce(
|
TapBounce(
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: const BoxDecoration(gradient: kGreenButtonGradient),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 50,
|
height: 50,
|
||||||
child: FilledButton(
|
child: FilledButton(
|
||||||
style:
|
style:
|
||||||
FilledButton.styleFrom(
|
FilledButton.styleFrom(
|
||||||
backgroundColor: _teal,
|
backgroundColor: Colors.transparent,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
shape: const StadiumBorder(),
|
shape: const StadiumBorder(),
|
||||||
textStyle: const TextStyle(
|
textStyle: const TextStyle(
|
||||||
@@ -427,9 +466,8 @@ class _AuthForm extends StatelessWidget {
|
|||||||
).copyWith(
|
).copyWith(
|
||||||
animationDuration: const Duration(milliseconds: 180),
|
animationDuration: const Duration(milliseconds: 180),
|
||||||
splashFactory: InkSparkle.splashFactory,
|
splashFactory: InkSparkle.splashFactory,
|
||||||
overlayColor: WidgetStateProperty.resolveWith<Color?>((
|
overlayColor: WidgetStateProperty.resolveWith<Color?>(
|
||||||
states,
|
(states) {
|
||||||
) {
|
|
||||||
if (states.contains(WidgetState.pressed)) {
|
if (states.contains(WidgetState.pressed)) {
|
||||||
return Colors.white.withValues(alpha: 0.14);
|
return Colors.white.withValues(alpha: 0.14);
|
||||||
}
|
}
|
||||||
@@ -438,7 +476,8 @@ class _AuthForm extends StatelessWidget {
|
|||||||
return Colors.white.withValues(alpha: 0.08);
|
return Colors.white.withValues(alpha: 0.08);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}),
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
onPressed: loading ? null : onSubmit,
|
onPressed: loading ? null : onSubmit,
|
||||||
child: loading
|
child: loading
|
||||||
@@ -456,15 +495,14 @@ class _AuthForm extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text(isLogin ? 'Entrar' : 'Criar Conta'),
|
Text(isLogin ? 'Entrar' : 'Criar Conta'),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
const Icon(
|
const Icon(Icons.arrow_forward_rounded, size: 18),
|
||||||
Icons.arrow_forward_rounded,
|
|
||||||
size: 18,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ class _LoggedHomeScreenState extends State<LoggedHomeScreen>
|
|||||||
static const Color _teal = Color(0xFF2F9E94);
|
static const Color _teal = Color(0xFF2F9E94);
|
||||||
static const String _kPendingQuizScopeKey = 'pending_quiz_scope_v1';
|
static const String _kPendingQuizScopeKey = 'pending_quiz_scope_v1';
|
||||||
|
|
||||||
static const double _collapsedAppBarHeight = 104;
|
static const double _collapsedAppBarHeight = 80;
|
||||||
static const double _expandedAppBarHeight = 180;
|
static const double _expandedAppBarHeight = 190;
|
||||||
static const double _nameOnlyAppBarHeight = 130;
|
static const double _nameOnlyAppBarHeight = 160;
|
||||||
|
|
||||||
int _index = 0;
|
int _index = 0;
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ class _LoggedHomeScreenState extends State<LoggedHomeScreen>
|
|||||||
: 'Configurações';
|
: 'Configurações';
|
||||||
final ShapeBorder appBarShape = _index == 0
|
final ShapeBorder appBarShape = _index == 0
|
||||||
? const RoundedRectangleBorder(
|
? const RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.vertical(bottom: Radius.circular(24)),
|
borderRadius: BorderRadius.vertical(bottom: Radius.circular(40)),
|
||||||
)
|
)
|
||||||
: const RoundedRectangleBorder(borderRadius: BorderRadius.zero);
|
: const RoundedRectangleBorder(borderRadius: BorderRadius.zero);
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ class _LoggedHomeScreenState extends State<LoggedHomeScreen>
|
|||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
flexibleSpace: ClipRRect(
|
flexibleSpace: ClipRRect(
|
||||||
borderRadius: BorderRadius.vertical(
|
borderRadius: BorderRadius.vertical(
|
||||||
bottom: Radius.circular(_index == 0 ? 24 : 0),
|
bottom: Radius.circular(_index == 0 ? 40 : 0),
|
||||||
),
|
),
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: const BoxDecoration(gradient: kAppBarGradient),
|
decoration: const BoxDecoration(gradient: kAppBarGradient),
|
||||||
@@ -272,20 +272,24 @@ class _LoggedHomeScreenState extends State<LoggedHomeScreen>
|
|||||||
Positioned(
|
Positioned(
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
top: toolbarHeight + 26,
|
top: toolbarHeight + 18,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
(_selectedChildName ?? '').trim(),
|
(_selectedChildName ?? '').trim(),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.w800,
|
fontWeight: FontWeight.w800,
|
||||||
color: Colors.white.withValues(alpha: 0.92),
|
color: Colors.white.withValues(
|
||||||
|
alpha: 0.92,
|
||||||
|
),
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else if ((_selectedChildName ?? '').trim().isNotEmpty)
|
else if ((_selectedChildName ?? '')
|
||||||
|
.trim()
|
||||||
|
.isNotEmpty)
|
||||||
Positioned(
|
Positioned(
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
@@ -297,7 +301,9 @@ class _LoggedHomeScreenState extends State<LoggedHomeScreen>
|
|||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.w800,
|
fontWeight: FontWeight.w800,
|
||||||
color: Colors.white.withValues(alpha: 0.92),
|
color: Colors.white.withValues(
|
||||||
|
alpha: 0.92,
|
||||||
|
),
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -307,7 +313,7 @@ class _LoggedHomeScreenState extends State<LoggedHomeScreen>
|
|||||||
Positioned(
|
Positioned(
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
bottom: 12,
|
bottom: 6,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: _RiskArcGauge(percent: percent),
|
child: _RiskArcGauge(percent: percent),
|
||||||
),
|
),
|
||||||
@@ -338,8 +344,9 @@ class _LoggedHomeScreenState extends State<LoggedHomeScreen>
|
|||||||
children: [
|
children: [
|
||||||
CircleAvatar(
|
CircleAvatar(
|
||||||
radius: 20,
|
radius: 20,
|
||||||
backgroundColor: Colors.white
|
backgroundColor: Colors.white.withValues(
|
||||||
.withValues(alpha: 0.25),
|
alpha: 0.25,
|
||||||
|
),
|
||||||
backgroundImage:
|
backgroundImage:
|
||||||
(_cachedPhotoUrl ?? '').isNotEmpty
|
(_cachedPhotoUrl ?? '').isNotEmpty
|
||||||
? NetworkImage(_cachedPhotoUrl!)
|
? NetworkImage(_cachedPhotoUrl!)
|
||||||
@@ -1132,33 +1139,55 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 14),
|
const SizedBox(height: 14),
|
||||||
SizedBox(
|
ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
gradient: kGreenButtonGradient,
|
||||||
|
),
|
||||||
|
child: SizedBox(
|
||||||
height: 46,
|
height: 46,
|
||||||
child: FilledButton(
|
child: FilledButton(
|
||||||
style: FilledButton.styleFrom(
|
style: FilledButton.styleFrom(
|
||||||
backgroundColor: const Color(0xFF2F9E94),
|
backgroundColor: Colors.transparent,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
shape: const StadiumBorder(),
|
shape: const StadiumBorder(),
|
||||||
textStyle: const TextStyle(fontWeight: FontWeight.w900),
|
textStyle: const TextStyle(
|
||||||
|
fontWeight: FontWeight.w900,
|
||||||
),
|
),
|
||||||
onPressed: () => Navigator.of(ctx).pop(ImageSource.camera),
|
),
|
||||||
|
onPressed: () =>
|
||||||
|
Navigator.of(ctx).pop(ImageSource.camera),
|
||||||
child: const Text('Câmera'),
|
child: const Text('Câmera'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
SizedBox(
|
ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
gradient: kGreenButtonGradient,
|
||||||
|
),
|
||||||
|
child: SizedBox(
|
||||||
height: 46,
|
height: 46,
|
||||||
child: FilledButton(
|
child: FilledButton(
|
||||||
style: FilledButton.styleFrom(
|
style: FilledButton.styleFrom(
|
||||||
backgroundColor: const Color(0xFF2F9E94),
|
backgroundColor: Colors.transparent,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
shape: const StadiumBorder(),
|
shape: const StadiumBorder(),
|
||||||
textStyle: const TextStyle(fontWeight: FontWeight.w900),
|
textStyle: const TextStyle(
|
||||||
|
fontWeight: FontWeight.w900,
|
||||||
),
|
),
|
||||||
onPressed: () => Navigator.of(ctx).pop(ImageSource.gallery),
|
),
|
||||||
|
onPressed: () =>
|
||||||
|
Navigator.of(ctx).pop(ImageSource.gallery),
|
||||||
child: const Text('Galeria'),
|
child: const Text('Galeria'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 42,
|
height: 42,
|
||||||
@@ -1193,22 +1222,17 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
final path = '$uid/profile.jpg';
|
final path = '$uid/profile.jpg';
|
||||||
await supabase.storage
|
await supabase.storage
|
||||||
.from('photos')
|
.from('photos')
|
||||||
.upload(
|
.upload(path, file, fileOptions: const FileOptions(upsert: true));
|
||||||
path,
|
|
||||||
file,
|
|
||||||
fileOptions: const FileOptions(upsert: true),
|
|
||||||
);
|
|
||||||
final publicUrl = supabase.storage.from('photos').getPublicUrl(path);
|
final publicUrl = supabase.storage.from('photos').getPublicUrl(path);
|
||||||
final url = '$publicUrl?t=${DateTime.now().millisecondsSinceEpoch}';
|
final url = '$publicUrl?t=${DateTime.now().millisecondsSinceEpoch}';
|
||||||
|
|
||||||
await supabase.from('profiles').upsert({
|
await supabase.from('profiles').upsert({'id': uid, 'photo_url': url});
|
||||||
'id': uid,
|
|
||||||
'photo_url': url,
|
|
||||||
});
|
|
||||||
|
|
||||||
await _loadPerfilData();
|
await _loadPerfilData();
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
context.findAncestorStateOfType<_LoggedHomeScreenState>()?.updateCachedPhoto(url);
|
context
|
||||||
|
.findAncestorStateOfType<_LoggedHomeScreenState>()
|
||||||
|
?.updateCachedPhoto(url);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
@@ -1239,16 +1263,21 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await supabase.from('children').delete().eq('id', childId);
|
final deleted = await supabase
|
||||||
|
.from('children')
|
||||||
|
.delete()
|
||||||
|
.eq('id', childId)
|
||||||
|
.select('id');
|
||||||
|
|
||||||
|
if (deleted.isEmpty) {
|
||||||
|
throw StateError('Sem permissão para remover esta criança.');
|
||||||
|
}
|
||||||
|
|
||||||
widget.onChildSelected(0, null, null);
|
widget.onChildSelected(0, null, null);
|
||||||
await _loadPerfilData();
|
await _loadPerfilData();
|
||||||
messenger.showSnackBar(
|
messenger.showSnackBar(const SnackBar(content: Text('Criança removida')));
|
||||||
const SnackBar(content: Text('Criança removida')),
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
messenger.showSnackBar(
|
messenger.showSnackBar(SnackBar(content: Text('Erro ao remover: $e')));
|
||||||
SnackBar(content: Text('Erro ao remover: $e')),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1270,10 +1299,7 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
|
|
||||||
if (result == null) return;
|
if (result == null) return;
|
||||||
|
|
||||||
final childMap = {
|
final childMap = {...result, 'owner_id': uid};
|
||||||
...result,
|
|
||||||
'owner_id': uid,
|
|
||||||
};
|
|
||||||
|
|
||||||
setState(() => _addingChild = true);
|
setState(() => _addingChild = true);
|
||||||
try {
|
try {
|
||||||
@@ -1467,8 +1493,7 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
const SizedBox(width: 14),
|
const SizedBox(width: 14),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
profileName,
|
profileName,
|
||||||
@@ -1570,9 +1595,7 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
child: Text(
|
child: Text(
|
||||||
'Nenhuma criança adicionada ainda.',
|
'Nenhuma criança adicionada ainda.',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.black.withValues(
|
color: Colors.black.withValues(alpha: 0.62),
|
||||||
alpha: 0.62,
|
|
||||||
),
|
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1585,13 +1608,9 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
final i = entry.key;
|
final i = entry.key;
|
||||||
final c = entry.value;
|
final c = entry.value;
|
||||||
final childId = (c['id'] ?? '').toString().trim();
|
final childId = (c['id'] ?? '').toString().trim();
|
||||||
final childName = (c['name'] ?? '')
|
final childName = (c['name'] ?? '').toString().trim();
|
||||||
.toString()
|
|
||||||
.trim();
|
|
||||||
final childAge = c['age'];
|
final childAge = c['age'];
|
||||||
final childGender = (c['gender'] ?? '')
|
final childGender = (c['gender'] ?? '').toString().trim();
|
||||||
.toString()
|
|
||||||
.trim();
|
|
||||||
final scopeId = '${uid}_$childId';
|
final scopeId = '${uid}_$childId';
|
||||||
|
|
||||||
final title = childName.isNotEmpty
|
final title = childName.isNotEmpty
|
||||||
@@ -1599,15 +1618,12 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
: 'Criança ${i + 1}';
|
: 'Criança ${i + 1}';
|
||||||
final subtitle = [
|
final subtitle = [
|
||||||
if (childAge != null) 'Idade: $childAge',
|
if (childAge != null) 'Idade: $childAge',
|
||||||
if (childGender.isNotEmpty)
|
if (childGender.isNotEmpty) 'Gênero: $childGender',
|
||||||
'Gênero: $childGender',
|
|
||||||
].join(' • ');
|
].join(' • ');
|
||||||
final bool selected = i == selectedIndex;
|
final bool selected = i == selectedIndex;
|
||||||
|
|
||||||
return FadeSlideIn(
|
return FadeSlideIn(
|
||||||
delay: Duration(
|
delay: Duration(milliseconds: 60 * i.clamp(0, 6)),
|
||||||
milliseconds: 60 * i.clamp(0, 6),
|
|
||||||
),
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(bottom: 12),
|
padding: const EdgeInsets.only(bottom: 12),
|
||||||
child: TapBounce(
|
child: TapBounce(
|
||||||
@@ -1631,24 +1647,19 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
? const Color(
|
? const Color(
|
||||||
0xFF2F9E94,
|
0xFF2F9E94,
|
||||||
).withValues(alpha: 0.45)
|
).withValues(alpha: 0.45)
|
||||||
: Colors.black.withValues(
|
: Colors.black.withValues(alpha: 0.10),
|
||||||
alpha: 0.10,
|
|
||||||
),
|
|
||||||
width: selected ? 1.6 : 1,
|
width: selected ? 1.6 : 1,
|
||||||
),
|
),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black.withValues(
|
color: Colors.black.withValues(alpha: 0.06),
|
||||||
alpha: 0.06,
|
|
||||||
),
|
|
||||||
blurRadius: 14,
|
blurRadius: 14,
|
||||||
offset: const Offset(0, 8),
|
offset: const Offset(0, 8),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -1688,8 +1699,9 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
color: const Color(
|
color: const Color(
|
||||||
0xFF2F9E94,
|
0xFF2F9E94,
|
||||||
).withValues(alpha: 0.10),
|
).withValues(alpha: 0.10),
|
||||||
borderRadius:
|
borderRadius: BorderRadius.circular(
|
||||||
BorderRadius.circular(999),
|
999,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
text,
|
text,
|
||||||
@@ -1724,11 +1736,17 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
TapBounce(
|
TapBounce(
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
gradient: kGreenButtonGradient,
|
||||||
|
),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 48,
|
height: 48,
|
||||||
child: FilledButton.icon(
|
child: FilledButton.icon(
|
||||||
style: FilledButton.styleFrom(
|
style: FilledButton.styleFrom(
|
||||||
backgroundColor: const Color(0xFF2F9E94),
|
backgroundColor: Colors.transparent,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
shape: const StadiumBorder(),
|
shape: const StadiumBorder(),
|
||||||
textStyle: const TextStyle(
|
textStyle: const TextStyle(
|
||||||
@@ -1743,6 +1761,8 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 22),
|
const SizedBox(height: 22),
|
||||||
TapBounce(
|
TapBounce(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
@@ -1755,9 +1775,7 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
width: 1.4,
|
width: 1.4,
|
||||||
),
|
),
|
||||||
shape: const StadiumBorder(),
|
shape: const StadiumBorder(),
|
||||||
textStyle: const TextStyle(
|
textStyle: const TextStyle(fontWeight: FontWeight.w800),
|
||||||
fontWeight: FontWeight.w800,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await supabase.auth.signOut();
|
await supabase.auth.signOut();
|
||||||
@@ -1777,7 +1795,6 @@ class _PerfilTabState extends State<_PerfilTab> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class _AddChildSheet extends StatefulWidget {
|
class _AddChildSheet extends StatefulWidget {
|
||||||
const _AddChildSheet();
|
const _AddChildSheet();
|
||||||
|
|
||||||
@@ -1869,8 +1886,8 @@ class _AddChildSheetState extends State<_AddChildSheet> {
|
|||||||
if (raw.isEmpty) return 'Informe a idade';
|
if (raw.isEmpty) return 'Informe a idade';
|
||||||
final age = int.tryParse(raw);
|
final age = int.tryParse(raw);
|
||||||
if (age == null) return 'Idade inválida';
|
if (age == null) return 'Idade inválida';
|
||||||
if (age < 0 || age > 17) {
|
if (age < 1 || age > 17) {
|
||||||
return 'Idade deve ser entre 0 e 17 anos';
|
return 'Idade deve ser entre 1 e 17 anos';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
@@ -1916,11 +1933,17 @@ class _AddChildSheetState extends State<_AddChildSheet> {
|
|||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TapBounce(
|
child: TapBounce(
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
gradient: kGreenButtonGradient,
|
||||||
|
),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 44,
|
height: 44,
|
||||||
child: FilledButton(
|
child: FilledButton(
|
||||||
style: FilledButton.styleFrom(
|
style: FilledButton.styleFrom(
|
||||||
backgroundColor: const Color(0xFF2F9E94),
|
backgroundColor: Colors.transparent,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
shape: const StadiumBorder(),
|
shape: const StadiumBorder(),
|
||||||
textStyle: const TextStyle(
|
textStyle: const TextStyle(
|
||||||
@@ -1933,6 +1956,8 @@ class _AddChildSheetState extends State<_AddChildSheet> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import '../main.dart' show supabase;
|
import '../main.dart' show supabase;
|
||||||
|
import '../widgets/app_gradients.dart';
|
||||||
import '../widgets/entrance.dart';
|
import '../widgets/entrance.dart';
|
||||||
import '../widgets/tap_bounce.dart';
|
import '../widgets/tap_bounce.dart';
|
||||||
import 'quiz_prefs.dart';
|
import 'quiz_prefs.dart';
|
||||||
@@ -173,8 +174,9 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
|
|||||||
Text(
|
Text(
|
||||||
'${clamped.toInt()}/${widget.maxScore}',
|
'${clamped.toInt()}/${widget.maxScore}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.black
|
color: Colors.black.withValues(
|
||||||
.withValues(alpha: 0.60),
|
alpha: 0.60,
|
||||||
|
),
|
||||||
fontWeight: FontWeight.w800,
|
fontWeight: FontWeight.w800,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -229,12 +231,18 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
|
|||||||
),
|
),
|
||||||
Center(
|
Center(
|
||||||
child: TapBounce(
|
child: TapBounce(
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
gradient: kGreenButtonGradient,
|
||||||
|
),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 260,
|
width: 260,
|
||||||
height: 46,
|
height: 46,
|
||||||
child: FilledButton(
|
child: FilledButton(
|
||||||
style: FilledButton.styleFrom(
|
style: FilledButton.styleFrom(
|
||||||
backgroundColor: const Color(0xFF2F9E94),
|
backgroundColor: Colors.transparent,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
shape: const StadiumBorder(),
|
shape: const StadiumBorder(),
|
||||||
textStyle: const TextStyle(
|
textStyle: const TextStyle(
|
||||||
@@ -244,13 +252,17 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
|
|||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await _saveResultFuture;
|
await _saveResultFuture;
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
Navigator.of(context).popUntil((r) => r.isFirst);
|
Navigator.of(
|
||||||
|
context,
|
||||||
|
).popUntil((r) => r.isFirst);
|
||||||
},
|
},
|
||||||
child: const Text('Avançar'),
|
child: const Text('Avançar'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -38,10 +38,7 @@ class CuriosidadeScreen extends StatelessWidget {
|
|||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
begin: Alignment.topCenter,
|
begin: Alignment.topCenter,
|
||||||
end: Alignment.bottomCenter,
|
end: Alignment.bottomCenter,
|
||||||
colors: [
|
colors: [Color(0xFFFFE6F1), Color(0xFFFFC9DF)],
|
||||||
Color(0xFFFFE6F1),
|
|
||||||
Color(0xFFFFC9DF),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -175,7 +172,9 @@ class _CuriosityTopicTile extends StatelessWidget {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white.withValues(alpha: 0.82),
|
color: Colors.white.withValues(alpha: 0.82),
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
border: Border.all(color: Colors.black.withValues(alpha: 0.08)),
|
border: Border.all(
|
||||||
|
color: Colors.black.withValues(alpha: 0.08),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
description,
|
description,
|
||||||
@@ -188,11 +187,17 @@ class _CuriosityTopicTile extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 14),
|
const SizedBox(height: 14),
|
||||||
TapBounce(
|
TapBounce(
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(999),
|
||||||
|
child: DecoratedBox(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
gradient: kGreenButtonGradient,
|
||||||
|
),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 44,
|
height: 44,
|
||||||
child: FilledButton(
|
child: FilledButton(
|
||||||
style: FilledButton.styleFrom(
|
style: FilledButton.styleFrom(
|
||||||
backgroundColor: const Color(0xFF2F9E94),
|
backgroundColor: Colors.transparent,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
shape: const StadiumBorder(),
|
shape: const StadiumBorder(),
|
||||||
textStyle: const TextStyle(
|
textStyle: const TextStyle(
|
||||||
@@ -204,6 +209,8 @@ class _CuriosityTopicTile extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -47,7 +47,23 @@ class _SettingsBodyState extends State<SettingsBody> {
|
|||||||
setState(() => _deletingAccount = true);
|
setState(() => _deletingAccount = true);
|
||||||
try {
|
try {
|
||||||
await supabase.from('children').delete().eq('owner_id', uid);
|
await supabase.from('children').delete().eq('owner_id', uid);
|
||||||
await supabase.from('profiles').delete().eq('id', uid);
|
|
||||||
|
// O Supabase não avisa quando uma política de RLS bloqueia silenciosamente
|
||||||
|
// uma operação: sem `.select()` para devolver as linhas apagadas não há
|
||||||
|
// como distinguir "0 linhas existiam" de "sem permissão para apagar".
|
||||||
|
final deletedProfile = await supabase
|
||||||
|
.from('profiles')
|
||||||
|
.delete()
|
||||||
|
.eq('id', uid)
|
||||||
|
.select('id');
|
||||||
|
|
||||||
|
if (deletedProfile.isEmpty) {
|
||||||
|
throw StateError(
|
||||||
|
'A base de dados recusou apagar o perfil (sem política de RLS '
|
||||||
|
'para DELETE). Os dados não foram removidos.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await supabase.auth.signOut();
|
await supabase.auth.signOut();
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@@ -11,8 +12,9 @@ import '../widgets/entrance.dart';
|
|||||||
import '../widgets/tap_bounce.dart';
|
import '../widgets/tap_bounce.dart';
|
||||||
|
|
||||||
// Video data structure - easily editable for future updates.
|
// Video data structure - easily editable for future updates.
|
||||||
// Episódios 1-7 tocam via YouTube (não listado); preencha youtubeId ao subir
|
// Episódios 1-10 tocam via YouTube (não listado). Episódios 11-13 ainda não
|
||||||
// cada vídeo. Episódios 8-13 continuam embutidos no app (assets/videos).
|
// foram subidos ao YouTube e continuam embutidos no app (assets/videos) até
|
||||||
|
// lá — depois de subidos, troque videoPath por youtubeId e apague o mp4.
|
||||||
class VideoData {
|
class VideoData {
|
||||||
final int id;
|
final int id;
|
||||||
final String title;
|
final String title;
|
||||||
@@ -35,61 +37,61 @@ final List<VideoData> videoList = [
|
|||||||
id: 1,
|
id: 1,
|
||||||
title: 'Episódio 1',
|
title: 'Episódio 1',
|
||||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
youtubeId: 'PJ58CZv4ECw',
|
||||||
),
|
),
|
||||||
VideoData(
|
VideoData(
|
||||||
id: 2,
|
id: 2,
|
||||||
title: 'Episódio 2',
|
title: 'Episódio 2',
|
||||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
youtubeId: 'y4_kWmZtAtg',
|
||||||
),
|
),
|
||||||
VideoData(
|
VideoData(
|
||||||
id: 3,
|
id: 3,
|
||||||
title: 'Episódio 3',
|
title: 'Episódio 3',
|
||||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
youtubeId: 'nD75Y5PuKTo',
|
||||||
),
|
),
|
||||||
VideoData(
|
VideoData(
|
||||||
id: 4,
|
id: 4,
|
||||||
title: 'Episódio 4',
|
title: 'Episódio 4',
|
||||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
youtubeId: 'yvFllWYeuLw',
|
||||||
),
|
),
|
||||||
VideoData(
|
VideoData(
|
||||||
id: 5,
|
id: 5,
|
||||||
title: 'Episódio 5',
|
title: 'Episódio 5',
|
||||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
youtubeId: 'DnhUa-T8_Ps',
|
||||||
),
|
),
|
||||||
VideoData(
|
VideoData(
|
||||||
id: 6,
|
id: 6,
|
||||||
title: 'Episódio 6',
|
title: 'Episódio 6',
|
||||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
youtubeId: 'zKt_iwkrjvo',
|
||||||
),
|
),
|
||||||
VideoData(
|
VideoData(
|
||||||
id: 7,
|
id: 7,
|
||||||
title: 'Episódio 7',
|
title: 'Episódio 7',
|
||||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
youtubeId: 'NpmQ2brap5A',
|
||||||
),
|
),
|
||||||
VideoData(
|
VideoData(
|
||||||
id: 8,
|
id: 8,
|
||||||
title: 'Episódio 8',
|
title: 'Episódio 8',
|
||||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||||
videoPath: 'assets/videos/episodio_08.mp4',
|
youtubeId: 'Wj3KYw9pBi0',
|
||||||
),
|
),
|
||||||
VideoData(
|
VideoData(
|
||||||
id: 9,
|
id: 9,
|
||||||
title: 'Episódio 9',
|
title: 'Episódio 9',
|
||||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||||
videoPath: 'assets/videos/episodio_09.mp4',
|
youtubeId: 'bOm9t61cT_U',
|
||||||
),
|
),
|
||||||
VideoData(
|
VideoData(
|
||||||
id: 10,
|
id: 10,
|
||||||
title: 'Episódio 10',
|
title: 'Episódio 10',
|
||||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||||
videoPath: 'assets/videos/episodio_10.mp4',
|
youtubeId: 'fAitMizbcms',
|
||||||
),
|
),
|
||||||
VideoData(
|
VideoData(
|
||||||
id: 11,
|
id: 11,
|
||||||
@@ -162,9 +164,8 @@ Future<void> showVideoPlayerDialog(BuildContext context, VideoData video) {
|
|||||||
).showSnackBar(const SnackBar(content: Text('Vídeo ainda não disponível')));
|
).showSnackBar(const SnackBar(content: Text('Vídeo ainda não disponível')));
|
||||||
return Future.value();
|
return Future.value();
|
||||||
}
|
}
|
||||||
return showDialog<void>(
|
return Navigator.of(context).push<void>(
|
||||||
context: context,
|
MaterialPageRoute(builder: (context) => _YoutubePlayerPage(video: video)),
|
||||||
builder: (context) => _YoutubePlayerDialog(video: video),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
@@ -577,16 +578,26 @@ class _VideoButton extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _YoutubePlayerDialog extends StatefulWidget {
|
/// Página cheia (não diálogo) para o player do YouTube. O botão de tela cheia
|
||||||
const _YoutubePlayerDialog({required this.video});
|
/// do próprio player força a rotação para paisagem via
|
||||||
|
/// `SystemChrome.setPreferredOrientations`; um `Dialog` de largura fixa não
|
||||||
|
/// se adapta a essa rotação e causa overflow gráfico.
|
||||||
|
///
|
||||||
|
/// Em paisagem/tela cheia, o vídeo é recortado ("cover", como Instagram/
|
||||||
|
/// TikTok) para preencher o ecrã todo sem barras pretas — em vez de manter
|
||||||
|
/// a proporção 16:9 do YouTube e sobrar espaço vazio quando o ecrã tem uma
|
||||||
|
/// proporção mais larga que 16:9 (ex.: a maioria dos telemóveis atuais).
|
||||||
|
class _YoutubePlayerPage extends StatefulWidget {
|
||||||
|
const _YoutubePlayerPage({required this.video});
|
||||||
|
|
||||||
final VideoData video;
|
final VideoData video;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<_YoutubePlayerDialog> createState() => _YoutubePlayerDialogState();
|
State<_YoutubePlayerPage> createState() => _YoutubePlayerPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _YoutubePlayerDialogState extends State<_YoutubePlayerDialog> {
|
class _YoutubePlayerPageState extends State<_YoutubePlayerPage>
|
||||||
|
with WidgetsBindingObserver {
|
||||||
late final YoutubePlayerController _controller;
|
late final YoutubePlayerController _controller;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -596,49 +607,111 @@ class _YoutubePlayerDialogState extends State<_YoutubePlayerDialog> {
|
|||||||
initialVideoId: widget.video.youtubeId!,
|
initialVideoId: widget.video.youtubeId!,
|
||||||
flags: const YoutubePlayerFlags(autoPlay: true, mute: false),
|
flags: const YoutubePlayerFlags(autoPlay: true, mute: false),
|
||||||
);
|
);
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeMetrics() {
|
||||||
|
final isLandscape =
|
||||||
|
PlatformDispatcher.instance.views.first.physicalSize.width >
|
||||||
|
PlatformDispatcher.instance.views.first.physicalSize.height;
|
||||||
|
if (isLandscape == _controller.value.isFullScreen) return;
|
||||||
|
_controller.updateValue(_controller.value.copyWith(isFullScreen: isLandscape));
|
||||||
|
if (isLandscape) {
|
||||||
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
||||||
|
} else {
|
||||||
|
SystemChrome.restoreSystemUIOverlays();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
|
SystemChrome.restoreSystemUIOverlays();
|
||||||
_controller.dispose();
|
_controller.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final size = MediaQuery.sizeOf(context);
|
return ValueListenableBuilder<YoutubePlayerValue>(
|
||||||
return Dialog(
|
valueListenable: _controller,
|
||||||
backgroundColor: Colors.transparent,
|
builder: (context, value, _) {
|
||||||
insetPadding: const EdgeInsets.all(16),
|
return PopScope(
|
||||||
child: Container(
|
canPop: !value.isFullScreen,
|
||||||
decoration: BoxDecoration(
|
onPopInvokedWithResult: (didPop, _) {
|
||||||
color: VideoScreen._accentPink.withValues(alpha: 0.15),
|
if (!didPop) _controller.toggleFullScreenMode();
|
||||||
borderRadius: BorderRadius.circular(24),
|
},
|
||||||
border: Border.all(color: VideoScreen._accentPink, width: 3),
|
child: Scaffold(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
appBar: value.isFullScreen
|
||||||
|
? null
|
||||||
|
: AppBar(
|
||||||
|
backgroundColor: VideoScreen._teal,
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
elevation: 0,
|
||||||
|
title: Text(
|
||||||
|
widget.video.title,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.w900),
|
||||||
),
|
),
|
||||||
child: ClipRRect(
|
),
|
||||||
borderRadius: BorderRadius.circular(21),
|
body: value.isFullScreen
|
||||||
|
? _CoverYoutubePlayer(controller: _controller)
|
||||||
|
: Center(
|
||||||
|
child: AspectRatio(
|
||||||
|
aspectRatio: 16 / 9,
|
||||||
|
child: YoutubePlayer(controller: _controller),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Preenche todo o espaço disponível recortando o vídeo (mantém a proporção
|
||||||
|
/// 16:9 real do YouTube, mas amplia e corta o excesso nas laterais ou em
|
||||||
|
/// cima/baixo em vez de deixar barras pretas). O player é sempre desenhado
|
||||||
|
/// no seu tamanho real (nunca reduzido a uma caixa minúscula), por isso o
|
||||||
|
/// recorte fica nítido, sem perda de qualidade.
|
||||||
|
class _CoverYoutubePlayer extends StatelessWidget {
|
||||||
|
const _CoverYoutubePlayer({required this.controller});
|
||||||
|
|
||||||
|
final YoutubePlayerController controller;
|
||||||
|
|
||||||
|
static const double _videoAspectRatio = 16 / 9;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final parentAspectRatio = constraints.maxWidth / constraints.maxHeight;
|
||||||
|
final double boxWidth;
|
||||||
|
final double boxHeight;
|
||||||
|
if (parentAspectRatio > _videoAspectRatio) {
|
||||||
|
boxWidth = constraints.maxWidth;
|
||||||
|
boxHeight = boxWidth / _videoAspectRatio;
|
||||||
|
} else {
|
||||||
|
boxHeight = constraints.maxHeight;
|
||||||
|
boxWidth = boxHeight * _videoAspectRatio;
|
||||||
|
}
|
||||||
|
return ClipRect(
|
||||||
|
child: OverflowBox(
|
||||||
|
maxWidth: boxWidth,
|
||||||
|
maxHeight: boxHeight,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: size.width * 0.9,
|
width: boxWidth,
|
||||||
child: Column(
|
height: boxHeight,
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: YoutubePlayer(
|
||||||
children: [
|
controller: controller,
|
||||||
YoutubePlayer(controller: _controller),
|
aspectRatio: _videoAspectRatio,
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
||||||
color: VideoScreen._accentPink.withValues(alpha: 0.15),
|
|
||||||
alignment: Alignment.centerRight,
|
|
||||||
child: IconButton(
|
|
||||||
icon: const Icon(Icons.close, color: Colors.white),
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
/// Gradiente usado em todas as app bars da aplicação — um destaque em verde
|
/// Gradiente usado em todas as app bars da aplicação.
|
||||||
/// vivo concentrado no canto superior direito, dissolvendo rapidamente para
|
|
||||||
/// o teal da marca no resto da barra.
|
|
||||||
const LinearGradient kAppBarGradient = LinearGradient(
|
const LinearGradient kAppBarGradient = LinearGradient(
|
||||||
begin: Alignment.topRight,
|
begin: Alignment.topRight,
|
||||||
end: Alignment.bottomLeft,
|
end: Alignment.bottomLeft,
|
||||||
colors: [Color(0xFF31C679), Color(0xFF2F9E94)],
|
colors: [Color(0xFF6BB79F), Color(0xFF6BB79F)],
|
||||||
stops: [0.0, 0.55],
|
);
|
||||||
|
|
||||||
|
/// Gradiente usado nos botões verdes da aplicação — um toque da cor da app
|
||||||
|
/// bar (#6BB79F) misturado com o teal original.
|
||||||
|
const LinearGradient kGreenButtonGradient = LinearGradient(
|
||||||
|
begin: Alignment.centerLeft,
|
||||||
|
end: Alignment.centerRight,
|
||||||
|
colors: [Color(0xFF2F9E94), Color(0xFF6BB79F)],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -71,9 +71,6 @@ flutter:
|
|||||||
- lottie/
|
- lottie/
|
||||||
- assets/Check-theeth.png
|
- assets/Check-theeth.png
|
||||||
- assets/mockup_images/
|
- assets/mockup_images/
|
||||||
- assets/videos/episodio_08.mp4
|
|
||||||
- assets/videos/episodio_09.mp4
|
|
||||||
- assets/videos/episodio_10.mp4
|
|
||||||
- assets/videos/episodio_11.mp4
|
- assets/videos/episodio_11.mp4
|
||||||
- assets/videos/episodio_12.mp4
|
- assets/videos/episodio_12.mp4
|
||||||
- assets/videos/episodio_13.mp4
|
- assets/videos/episodio_13.mp4
|
||||||
|
|||||||
Reference in New Issue
Block a user