Atualização geral de optimazação e desing
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
import 'main.dart' show supabase;
|
||||
import 'home_screen.dart';
|
||||
import 'logged_home.dart';
|
||||
|
||||
@@ -14,10 +15,11 @@ class AuthGate extends StatelessWidget {
|
||||
return ValueListenableBuilder<bool>(
|
||||
valueListenable: forceHomeScreen,
|
||||
builder: (context, forcedHome, _) {
|
||||
return StreamBuilder<User?>(
|
||||
stream: FirebaseAuth.instance.authStateChanges(),
|
||||
return StreamBuilder<AuthState>(
|
||||
stream: supabase.auth.onAuthStateChange,
|
||||
initialData: AuthState(AuthChangeEvent.initialSession, supabase.auth.currentSession),
|
||||
builder: (context, snapshot) {
|
||||
final user = snapshot.data;
|
||||
final user = snapshot.data?.session?.user;
|
||||
|
||||
final Widget child;
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
|
||||
@@ -66,29 +66,6 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(
|
||||
0xFF2F9E94,
|
||||
).withValues(alpha: 0.18),
|
||||
blurRadius: 24,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.medical_services_rounded,
|
||||
size: 38,
|
||||
color: Color(0xFF2F9E94),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
const Text(
|
||||
'Check-Teeth Kids',
|
||||
textAlign: TextAlign.center,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,94 +1,21 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
import 'dart:math' as math;
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
import '../main.dart' show supabase;
|
||||
|
||||
Future<void> showLoginSheet(BuildContext context) {
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
showDragHandle: true,
|
||||
backgroundColor: const Color(0xFFFFE6F1),
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
||||
),
|
||||
builder: (ctx) => const _AnimatedAuthSheet(child: LoginBottomSheet()),
|
||||
builder: (ctx) => const LoginBottomSheet(),
|
||||
);
|
||||
}
|
||||
|
||||
class _AnimatedAuthSheet extends StatelessWidget {
|
||||
const _AnimatedAuthSheet({required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
const topRadius = Radius.circular(20);
|
||||
|
||||
return TweenAnimationBuilder<double>(
|
||||
tween: Tween<double>(begin: 0.0, end: 1.0),
|
||||
duration: const Duration(milliseconds: 260),
|
||||
curve: Curves.easeOutCubic,
|
||||
builder: (context, t, w) {
|
||||
return Opacity(
|
||||
opacity: t,
|
||||
child: Transform.translate(
|
||||
offset: Offset(0, (1 - t) * 12),
|
||||
child: w,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: topRadius),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xFFFFE6F1),
|
||||
Color(0xFFFFC9DF),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: -size.width * 0.38,
|
||||
bottom: -size.width * 0.45,
|
||||
child: IgnorePointer(
|
||||
child: SizedBox(
|
||||
width: size.width * 1.05,
|
||||
height: size.width * 1.05,
|
||||
child: Transform.rotate(
|
||||
angle: 28 * math.pi / 180,
|
||||
child: Opacity(
|
||||
opacity: 0.95,
|
||||
child: Lottie.asset(
|
||||
'lottie/Liquid waves.json',
|
||||
fit: BoxFit.cover,
|
||||
repeat: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LoginBottomSheet extends StatefulWidget {
|
||||
const LoginBottomSheet({super.key});
|
||||
|
||||
@@ -113,119 +40,106 @@ class _LoginBottomSheetState extends State<LoginBottomSheet> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewInsets = MediaQuery.viewInsetsOf(context);
|
||||
const accentPink = Color(0xFFFF55A7);
|
||||
const primaryTeal = Color(0xFF2F9E94);
|
||||
final underlineBorder = UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black.withValues(alpha: 0.20)),
|
||||
);
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 12,
|
||||
bottom: 16 + viewInsets.bottom,
|
||||
),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 520),
|
||||
child: SingleChildScrollView(
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
final bottomInset = MediaQuery.viewInsetsOf(context).bottom;
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(18, 6, 18, 18 + bottomInset),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
'Entrar',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w900,
|
||||
color: Color(0xFFFF55A7),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.82),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: Colors.black.withValues(alpha: 0.08)),
|
||||
),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: const InputDecoration(labelText: 'Email'),
|
||||
validator: (v) {
|
||||
final value = (v ?? '').trim();
|
||||
if (value.isEmpty) return 'Informe seu email';
|
||||
if (!value.contains('@')) return 'Email inválido';
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
textInputAction: TextInputAction.done,
|
||||
decoration: const InputDecoration(labelText: 'Senha'),
|
||||
validator: (v) {
|
||||
final value = (v ?? '');
|
||||
if (value.isEmpty) return 'Informe sua senha';
|
||||
if (value.length < 6) return 'Mínimo de 6 caracteres';
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
Center(
|
||||
child: Container(
|
||||
width: 46,
|
||||
height: 5,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.10),
|
||||
borderRadius: BorderRadius.circular(99),
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 44,
|
||||
child: TextButton(
|
||||
onPressed: _loading
|
||||
? null
|
||||
: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
const Text(
|
||||
'Entrar',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: accentPink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Email',
|
||||
border: underlineBorder,
|
||||
enabledBorder: underlineBorder,
|
||||
focusedBorder: underlineBorder.copyWith(
|
||||
borderSide: const BorderSide(color: primaryTeal, width: 1.6),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 44,
|
||||
child: FilledButton(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF2F9E94),
|
||||
foregroundColor: Colors.white,
|
||||
shape: const StadiumBorder(),
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.w900),
|
||||
),
|
||||
onPressed: _loading ? null : _submit,
|
||||
child: _loading
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Text('Entrar'),
|
||||
),
|
||||
floatingLabelStyle: const TextStyle(color: primaryTeal, fontWeight: FontWeight.w700),
|
||||
),
|
||||
validator: (v) {
|
||||
final value = (v ?? '').trim();
|
||||
if (value.isEmpty) return 'Informe seu email';
|
||||
if (!value.contains('@')) return 'Email inválido';
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
textInputAction: TextInputAction.done,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Senha',
|
||||
border: underlineBorder,
|
||||
enabledBorder: underlineBorder,
|
||||
focusedBorder: underlineBorder.copyWith(
|
||||
borderSide: const BorderSide(color: primaryTeal, width: 1.6),
|
||||
),
|
||||
floatingLabelStyle: const TextStyle(color: primaryTeal, fontWeight: FontWeight.w700),
|
||||
),
|
||||
validator: (v) {
|
||||
final value = (v ?? '');
|
||||
if (value.isEmpty) return 'Informe sua senha';
|
||||
if (value.length < 6) return 'Mínimo de 6 caracteres';
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
height: 46,
|
||||
child: FilledButton(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: primaryTeal,
|
||||
foregroundColor: const Color.fromARGB(255, 255, 255, 255),
|
||||
shape: const StadiumBorder(),
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.w800),
|
||||
),
|
||||
onPressed: _loading ? null : _submit,
|
||||
child: _loading
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Text('Entrar'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextButton(
|
||||
onPressed: _loading ? null : () => Navigator.of(context).pop(),
|
||||
child: const Text('Fechar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -239,17 +153,14 @@ class _LoginBottomSheetState extends State<LoginBottomSheet> {
|
||||
final email = _emailController.text.trim();
|
||||
final password = _passwordController.text;
|
||||
|
||||
await FirebaseAuth.instance.signInWithEmailAndPassword(
|
||||
email: email,
|
||||
password: password,
|
||||
);
|
||||
await supabase.auth.signInWithPassword(email: email, password: password);
|
||||
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Login efetuado')),
|
||||
);
|
||||
} on FirebaseAuthException catch (e) {
|
||||
} on AuthException catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(_friendlyAuthError(e))),
|
||||
@@ -264,18 +175,14 @@ class _LoginBottomSheetState extends State<LoginBottomSheet> {
|
||||
}
|
||||
}
|
||||
|
||||
String _friendlyAuthError(FirebaseAuthException e) {
|
||||
String _friendlyAuthError(AuthException e) {
|
||||
switch (e.code) {
|
||||
case 'invalid-email':
|
||||
return 'Email inválido.';
|
||||
case 'user-disabled':
|
||||
return 'Usuário desativado.';
|
||||
case 'user-not-found':
|
||||
case 'wrong-password':
|
||||
case 'invalid-credential':
|
||||
case 'invalid_credentials':
|
||||
return 'Email ou senha incorretos.';
|
||||
case 'user_not_found':
|
||||
return 'Usuário não encontrado.';
|
||||
default:
|
||||
return e.message ?? 'Falha de autenticação.';
|
||||
return e.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,90 +1,22 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import '../main.dart' show supabase;
|
||||
|
||||
Future<void> showRegisterSheet(BuildContext context) {
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
showDragHandle: true,
|
||||
backgroundColor: const Color(0xFFFFE6F1),
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
||||
),
|
||||
builder: (ctx) => const _AnimatedAuthSheet(child: RegisterBottomSheet()),
|
||||
builder: (ctx) => const RegisterBottomSheet(),
|
||||
);
|
||||
}
|
||||
|
||||
class _AnimatedAuthSheet extends StatelessWidget {
|
||||
const _AnimatedAuthSheet({required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
const topRadius = Radius.circular(20);
|
||||
|
||||
return TweenAnimationBuilder<double>(
|
||||
tween: Tween<double>(begin: 0.0, end: 1.0),
|
||||
duration: const Duration(milliseconds: 260),
|
||||
curve: Curves.easeOutCubic,
|
||||
builder: (context, t, w) {
|
||||
return Opacity(
|
||||
opacity: t,
|
||||
child: Transform.translate(offset: Offset(0, (1 - t) * 12), child: w),
|
||||
);
|
||||
},
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: topRadius),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFFFE6F1), Color(0xFFFFC9DF)],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: -size.width * 0.38,
|
||||
bottom: -size.width * 0.45,
|
||||
child: IgnorePointer(
|
||||
child: SizedBox(
|
||||
width: size.width * 1.05,
|
||||
height: size.width * 1.05,
|
||||
child: Transform.rotate(
|
||||
angle: 28 * math.pi / 180,
|
||||
child: Opacity(
|
||||
opacity: 0.95,
|
||||
child: Lottie.asset(
|
||||
'lottie/Liquid waves.json',
|
||||
fit: BoxFit.cover,
|
||||
repeat: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RegisterBottomSheet extends StatefulWidget {
|
||||
const RegisterBottomSheet({super.key});
|
||||
|
||||
@@ -106,15 +38,11 @@ class _RegisterBottomSheetState extends State<RegisterBottomSheet> {
|
||||
required String name,
|
||||
required String email,
|
||||
}) async {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.set({
|
||||
'name': name,
|
||||
'email': email,
|
||||
'createdAt': FieldValue.serverTimestamp(),
|
||||
}, SetOptions(merge: true))
|
||||
.timeout(const Duration(seconds: 20));
|
||||
await supabase.from('profiles').upsert({
|
||||
'id': uid,
|
||||
'name': name,
|
||||
'email': email,
|
||||
}).timeout(const Duration(seconds: 20));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -127,162 +55,120 @@ class _RegisterBottomSheetState extends State<RegisterBottomSheet> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final viewInsets = MediaQuery.viewInsetsOf(context);
|
||||
const accentPink = Color(0xFFFF55A7);
|
||||
const primaryTeal = Color(0xFF2F9E94);
|
||||
final underlineBorder = UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.black.withValues(alpha: 0.20)),
|
||||
);
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 12,
|
||||
bottom: 16 + viewInsets.bottom,
|
||||
),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxHeight: 560),
|
||||
child: SingleChildScrollView(
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
final bottomInset = MediaQuery.viewInsetsOf(context).bottom;
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(18, 6, 18, 18 + bottomInset),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
'Criar conta',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w900,
|
||||
color: Color(0xFFFF55A7),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.82),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: Colors.black.withValues(alpha: 0.08)),
|
||||
),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: const InputDecoration(labelText: 'Nome'),
|
||||
validator: (v) {
|
||||
if (v == null || v.trim().isEmpty) {
|
||||
return 'Informe seu nome';
|
||||
}
|
||||
if (v.trim().length < 2) {
|
||||
return 'Nome muito curto';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: const InputDecoration(labelText: 'Email'),
|
||||
validator: (v) {
|
||||
final value = (v ?? '').trim();
|
||||
if (value.isEmpty) return 'Informe seu email';
|
||||
if (!value.contains('@')) return 'Email inválido';
|
||||
return null;
|
||||
},
|
||||
),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
textInputAction: TextInputAction.done,
|
||||
decoration: const InputDecoration(labelText: 'Senha'),
|
||||
validator: (v) {
|
||||
final value = (v ?? '');
|
||||
if (value.isEmpty) return 'Informe sua senha';
|
||||
if (value.length < 6) return 'Mínimo de 6 caracteres';
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
Center(
|
||||
child: Container(
|
||||
width: 46,
|
||||
height: 5,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.10),
|
||||
borderRadius: BorderRadius.circular(99),
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 44,
|
||||
child: TextButton(
|
||||
onPressed: _loading
|
||||
? null
|
||||
: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
const Text(
|
||||
'Criar conta',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: accentPink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Nome',
|
||||
border: underlineBorder,
|
||||
enabledBorder: underlineBorder,
|
||||
focusedBorder: underlineBorder.copyWith(
|
||||
borderSide: const BorderSide(
|
||||
color: primaryTeal,
|
||||
width: 1.6,
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
height: 44,
|
||||
child: FilledButton(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF2F9E94),
|
||||
foregroundColor: Colors.white,
|
||||
shape: const StadiumBorder(),
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.w900),
|
||||
),
|
||||
),
|
||||
floatingLabelStyle: const TextStyle(
|
||||
color: primaryTeal,
|
||||
fontWeight: FontWeight.w700,
|
||||
onPressed: _loading ? null : _submit,
|
||||
child: _loading
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Text('Registrar'),
|
||||
),
|
||||
),
|
||||
validator: (v) {
|
||||
if (v == null || v.trim().isEmpty) {
|
||||
return 'Informe seu nome';
|
||||
}
|
||||
if (v.trim().length < 2) {
|
||||
return 'Nome muito curto';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextFormField(
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Email',
|
||||
border: underlineBorder,
|
||||
enabledBorder: underlineBorder,
|
||||
focusedBorder: underlineBorder.copyWith(
|
||||
borderSide: const BorderSide(
|
||||
color: primaryTeal,
|
||||
width: 1.6,
|
||||
),
|
||||
),
|
||||
floatingLabelStyle: const TextStyle(
|
||||
color: primaryTeal,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
validator: (v) {
|
||||
final value = (v ?? '').trim();
|
||||
if (value.isEmpty) return 'Informe seu email';
|
||||
if (!value.contains('@')) return 'Email inválido';
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: true,
|
||||
textInputAction: TextInputAction.done,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Senha',
|
||||
border: underlineBorder,
|
||||
enabledBorder: underlineBorder,
|
||||
focusedBorder: underlineBorder.copyWith(
|
||||
borderSide: const BorderSide(
|
||||
color: primaryTeal,
|
||||
width: 1.6,
|
||||
),
|
||||
),
|
||||
floatingLabelStyle: const TextStyle(
|
||||
color: primaryTeal,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
validator: (v) {
|
||||
final value = (v ?? '');
|
||||
if (value.isEmpty) return 'Informe sua senha';
|
||||
if (value.length < 6) return 'Mínimo de 6 caracteres';
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
height: 46,
|
||||
child: FilledButton(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: primaryTeal,
|
||||
foregroundColor: Colors.white,
|
||||
shape: const StadiumBorder(),
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.w800),
|
||||
),
|
||||
onPressed: _loading ? null : _submit,
|
||||
child: _loading
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Text('Registrar'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextButton(
|
||||
onPressed: _loading
|
||||
? null
|
||||
: () => Navigator.of(context).pop(),
|
||||
child: const Text('Fechar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -297,21 +183,25 @@ class _RegisterBottomSheetState extends State<RegisterBottomSheet> {
|
||||
final email = _emailController.text.trim();
|
||||
final password = _passwordController.text;
|
||||
|
||||
final credential = await FirebaseAuth.instance
|
||||
.createUserWithEmailAndPassword(email: email, password: password)
|
||||
final response = await supabase.auth
|
||||
.signUp(
|
||||
email: email,
|
||||
password: password,
|
||||
data: {'name': name},
|
||||
)
|
||||
.timeout(const Duration(seconds: 20));
|
||||
|
||||
final user = credential.user;
|
||||
final user = response.user;
|
||||
if (user == null) {
|
||||
throw StateError('Usuário não encontrado após criar conta.');
|
||||
}
|
||||
|
||||
final uid = user.uid;
|
||||
final uid = user.id;
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
// Fecha o sheet imediatamente após autenticar.
|
||||
// As gravações no Firestore seguem em background para não travar a UI.
|
||||
// As gravações no banco seguem em background para não travar a UI.
|
||||
Navigator.of(context).pop();
|
||||
|
||||
unawaited(
|
||||
@@ -321,7 +211,7 @@ class _RegisterBottomSheetState extends State<RegisterBottomSheet> {
|
||||
email: email,
|
||||
).catchError((_) {}),
|
||||
);
|
||||
} on FirebaseAuthException catch (e) {
|
||||
} on AuthException catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
@@ -345,16 +235,15 @@ class _RegisterBottomSheetState extends State<RegisterBottomSheet> {
|
||||
}
|
||||
}
|
||||
|
||||
String _friendlyAuthError(FirebaseAuthException e) {
|
||||
String _friendlyAuthError(AuthException e) {
|
||||
switch (e.code) {
|
||||
case 'invalid-email':
|
||||
return 'Email inválido.';
|
||||
case 'email-already-in-use':
|
||||
case 'email_exists':
|
||||
case 'user_already_exists':
|
||||
return 'Este email já está em uso.';
|
||||
case 'weak-password':
|
||||
case 'weak_password':
|
||||
return 'Senha fraca. Use pelo menos 6 caracteres.';
|
||||
default:
|
||||
return e.message ?? 'Falha de autenticação.';
|
||||
return e.message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'gates/debug_launch_gate.dart';
|
||||
|
||||
const String supabaseUrl = 'https://mannjismlhlwaqqqnvog.supabase.co';
|
||||
const String supabaseAnonKey =
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1hbm5qaXNtbGhsd2FxcXFudm9nIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Nzk3MjU3MjEsImV4cCI6MjA5NTMwMTcyMX0.hF5tD1n7t_WSDLIesu1xcBHhzHouAVUCP8tUDDwUmDw';
|
||||
|
||||
SupabaseClient get supabase => Supabase.instance.client;
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
@@ -14,7 +20,7 @@ Future<void> main() async {
|
||||
};
|
||||
|
||||
runZonedGuarded(() async {
|
||||
await Firebase.initializeApp();
|
||||
await Supabase.initialize(url: supabaseUrl, publishableKey: supabaseAnonKey);
|
||||
runApp(const MyApp());
|
||||
}, (error, stack) {
|
||||
debugPrint('UNCAUGHT: $error');
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
# Sistema de Quiz Extendido - Check-Teeth Kids
|
||||
|
||||
## Novos Arquivos Criados
|
||||
|
||||
### 1. `quiz_extended.dart`
|
||||
Contém 15 novas telas de quiz sequenciais (Quiz 6-20) com temas educativos sobre saúde bucal:
|
||||
|
||||
- **Quiz 6**: Tipos de escova para crianças
|
||||
- **Quiz 7**: Alimentos que causam cáries
|
||||
- **Quiz 8**: Primeira visita ao dentista
|
||||
- **Quiz 9**: Uso de chupeta
|
||||
- **Quiz 10**: Flúor na água
|
||||
- **Quiz 11**: Escovação noturna
|
||||
- **Quiz 12**: Bebidas ácidas
|
||||
- **Quiz 13**: Importância dos dentes de leite
|
||||
- **Quiz 14**: Técnica de escovação
|
||||
- **Quiz 15**: Enxaguante bucal infantil
|
||||
- **Quiz 16**: Lanches escolares saudáveis
|
||||
- **Quiz 17**: Traumas dentários
|
||||
- **Quiz 18**: Problemas na mordida
|
||||
- **Quiz 19**: Gengivas sangrando
|
||||
- **Quiz 20**: Selantes dentários
|
||||
|
||||
### 2. `quiz_random.dart`
|
||||
Sistema de quiz aleatório com 15 perguntas selecionadas aleatoriamente a cada sessão.
|
||||
|
||||
## Como Usar
|
||||
|
||||
### Para Quiz Sequencial Extendido (20 perguntas):
|
||||
```dart
|
||||
import 'quiz_extended.dart';
|
||||
|
||||
// Para iniciar do Quiz 6:
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const Quiz6Screen()),
|
||||
);
|
||||
|
||||
// Para conectar ao final do Quiz 5, modifique quiz5.dart:
|
||||
nextRoute: (context, nextScore) => MaterialPageRoute<void>(
|
||||
builder: (_) => Quiz6Screen(currentScore: nextScore, scopeId: scopeId),
|
||||
),
|
||||
```
|
||||
|
||||
### Para Quiz Aleatório (15 perguntas):
|
||||
```dart
|
||||
import 'quiz_random.dart';
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const QuizRandomScreen()),
|
||||
);
|
||||
```
|
||||
|
||||
## Sistema de Pontuação
|
||||
|
||||
- **Quiz Sequencial**: 20 perguntas × 5 pontos = máximo 100 pontos
|
||||
- **Quiz Aleatório**: 15 perguntas × 5 pontos = máximo 75 pontos
|
||||
- **Sistema de pesos**: 2 (melhor) a 5 (pior) pontos
|
||||
|
||||
## Estrutura das Perguntas
|
||||
|
||||
Cada quiz segue o padrão:
|
||||
```dart
|
||||
QuizQuestionScreen(
|
||||
title: 'Quiz X/20',
|
||||
question: 'Pergunta educativa...',
|
||||
answers: [
|
||||
QuizAnswer(title: 'Resposta A', description: 'Explicação...', weight: 2),
|
||||
QuizAnswer(title: 'Resposta B', description: 'Explicação...', weight: 5),
|
||||
QuizAnswer(title: 'Resposta C', description: 'Explicação...', weight: 3),
|
||||
],
|
||||
currentScore: currentScore,
|
||||
nextRoute: (context, nextScore) => MaterialPageRoute(...),
|
||||
showBackButton: true,
|
||||
);
|
||||
```
|
||||
|
||||
## Temas Abordados
|
||||
|
||||
### 🦷 Higiene Oral
|
||||
- Tempo e técnica de escovação
|
||||
- Tipos de escova e pasta de dente
|
||||
- Uso de fio dental e enxaguante
|
||||
|
||||
### 🍎 Nutrição e Saúde
|
||||
- Alimentos prejudiciais e benéficos
|
||||
- Bebidas ácidas vs neutras
|
||||
- Lanches escolares saudáveis
|
||||
|
||||
### 👶 Desenvolvimento Infantil
|
||||
- Dentes de leite e permanentes
|
||||
- Hábitos como chupeta e sucção
|
||||
- Primeira visita ao dentista
|
||||
|
||||
### 🔬 Prevenção e Tratamento
|
||||
- Flúor e selantes
|
||||
- Traumas dentários
|
||||
- Problemas gengivais
|
||||
|
||||
## Integração com Sistema Existente
|
||||
|
||||
Os novos quizzes são totalmente compatíveis com:
|
||||
- ✅ Sistema de pontuação existente
|
||||
- ✅ Tela de resultados (`QuizResultScreen`)
|
||||
- ✅ Navegação e animações
|
||||
- ✅ Design e cores do app
|
||||
- ✅ Firebase (scopeId)
|
||||
|
||||
## Personalização
|
||||
|
||||
Para modificar o quiz aleatório:
|
||||
```dart
|
||||
// Em quiz_random.dart, altere o número de perguntas:
|
||||
final List<QuizQuestion> _selectedQuestions = _allQuestions.take(10).toList(); // 10 perguntas
|
||||
```
|
||||
|
||||
Para adicionar novas perguntas:
|
||||
```dart
|
||||
// Adicione ao final da lista _allQuestions em quiz_random.dart
|
||||
QuizQuestion(
|
||||
id: 16,
|
||||
title: 'Quiz 16/15',
|
||||
question: 'Nova pergunta...',
|
||||
answers: [...],
|
||||
),
|
||||
```
|
||||
|
||||
## Teste e Validação
|
||||
|
||||
Os arquivos foram testados com:
|
||||
- ✅ `flutter analyze` - sem erros
|
||||
- ✅ Estrutura compatível com código existente
|
||||
- ✅ Importações corretas
|
||||
- ✅ Navegação funcional
|
||||
|
||||
---
|
||||
|
||||
*Criado em 01/05/2026*
|
||||
*Total de perguntas: 35 (5 originais + 15 sequenciais + 15 aleatórias)*
|
||||
@@ -14,43 +14,29 @@ class Quiz1Screen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return QuizQuestionScreen(
|
||||
title: 'Quiz 1/26',
|
||||
question:
|
||||
'Qual das seguintes imagens se assemelha à face do seu filho/a?',
|
||||
question: 'O rosto do seu filho/a se parece com o desta imagem?',
|
||||
questionImagePaths: const ['assets/mockup_images/2.jpeg'],
|
||||
suggestedYoutubeId: '', // TODO: colar o ID do YouTube do Episódio 1
|
||||
suggestedVideoTitle: 'Ver vídeo: Episódio 1',
|
||||
answers: const [
|
||||
QuizAnswer(
|
||||
title: 'Opção A',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à face do seu filho/a',
|
||||
title: 'Sim',
|
||||
description: 'O rosto se assemelha à imagem',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/face_a.png',
|
||||
value: 'sim',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção B',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à face do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/face_b.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção C',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à face do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/face_c.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção D',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à face do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/face_d.png',
|
||||
title: 'Não',
|
||||
description: 'O rosto não se assemelha à imagem',
|
||||
weight: 1,
|
||||
value: 'nao',
|
||||
),
|
||||
],
|
||||
currentScore: currentScore,
|
||||
nextRoute: (context, nextScore) => MaterialPageRoute<void>(
|
||||
builder: (_) => Quiz2Screen(currentScore: nextScore, scopeId: scopeId),
|
||||
),
|
||||
answerType: QuizAnswerType.image,
|
||||
answerType: QuizAnswerType.yesNo,
|
||||
showBackButton: false,
|
||||
);
|
||||
}
|
||||
@@ -68,42 +54,29 @@ class Quiz2Screen extends StatelessWidget {
|
||||
return QuizQuestionScreen(
|
||||
title: 'Quiz 2/26',
|
||||
question:
|
||||
'Qual das seguintes imagens se assemelha à boca do seu filho/a?',
|
||||
'A boca do seu filho/a fica habitualmente na posição desta imagem (entreaberta)?',
|
||||
questionImagePaths: const ['assets/mockup_images/4.jpeg'],
|
||||
suggestedYoutubeId: '', // TODO: colar o ID do YouTube do Episódio 2
|
||||
suggestedVideoTitle: 'Ver vídeo: Episódio 2',
|
||||
answers: const [
|
||||
QuizAnswer(
|
||||
title: 'Opção A',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à boca do seu filho/a',
|
||||
title: 'Sim',
|
||||
description: 'A boca fica habitualmente entreaberta',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/mouth_a.png',
|
||||
value: 'sim',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção B',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à boca do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/mouth_b.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção C',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à boca do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/mouth_c.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção D',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à boca do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/mouth_d.png',
|
||||
title: 'Não',
|
||||
description: 'A boca fica habitualmente fechada',
|
||||
weight: 1,
|
||||
value: 'nao',
|
||||
),
|
||||
],
|
||||
currentScore: currentScore,
|
||||
nextRoute: (context, nextScore) => MaterialPageRoute<void>(
|
||||
builder: (_) => Quiz3Screen(currentScore: nextScore, scopeId: scopeId),
|
||||
),
|
||||
answerType: QuizAnswerType.image,
|
||||
answerType: QuizAnswerType.yesNo,
|
||||
showBackButton: true,
|
||||
);
|
||||
}
|
||||
@@ -120,43 +93,29 @@ class Quiz3Screen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return QuizQuestionScreen(
|
||||
title: 'Quiz 3/26',
|
||||
question:
|
||||
'Qual das seguintes imagens se assemelha às olheiras do seu filho/a?',
|
||||
question: 'O seu filho/a tem olheiras semelhantes às desta imagem?',
|
||||
questionImagePaths: const ['assets/mockup_images/8.jpeg'],
|
||||
suggestedYoutubeId: '', // TODO: colar o ID do YouTube do Episódio 3
|
||||
suggestedVideoTitle: 'Ver vídeo: Episódio 3',
|
||||
answers: const [
|
||||
QuizAnswer(
|
||||
title: 'Opção A',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha às olheiras do seu filho/a',
|
||||
title: 'Sim',
|
||||
description: 'Tem olheiras semelhantes à imagem',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/dark_circles_a.png',
|
||||
value: 'sim',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção B',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha às olheiras do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/dark_circles_b.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção C',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha às olheiras do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/dark_circles_c.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção D',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha às olheiras do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/dark_circles_d.png',
|
||||
title: 'Não',
|
||||
description: 'Não tem olheiras semelhantes à imagem',
|
||||
weight: 1,
|
||||
value: 'nao',
|
||||
),
|
||||
],
|
||||
currentScore: currentScore,
|
||||
nextRoute: (context, nextScore) => MaterialPageRoute<void>(
|
||||
builder: (_) => Quiz4Screen(currentScore: nextScore, scopeId: scopeId),
|
||||
),
|
||||
answerType: QuizAnswerType.image,
|
||||
answerType: QuizAnswerType.yesNo,
|
||||
showBackButton: true,
|
||||
);
|
||||
}
|
||||
@@ -174,42 +133,29 @@ class Quiz4Screen extends StatelessWidget {
|
||||
return QuizQuestionScreen(
|
||||
title: 'Quiz 4/26',
|
||||
question:
|
||||
'Qual das seguintes imagens se assemelha ao queixo do seu filho/a com a boca fechada?',
|
||||
'Com a boca fechada, o queixo do seu filho/a se parece com o desta imagem?',
|
||||
questionImagePaths: const ['assets/mockup_images/6.jpeg'],
|
||||
suggestedYoutubeId: '', // TODO: colar o ID do YouTube do Episódio 4
|
||||
suggestedVideoTitle: 'Ver vídeo: Episódio 4',
|
||||
answers: const [
|
||||
QuizAnswer(
|
||||
title: 'Opção A',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha ao queixo do seu filho/a',
|
||||
title: 'Sim',
|
||||
description: 'O queixo se assemelha à imagem',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/chin_a.png',
|
||||
value: 'sim',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção B',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha ao queixo do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/chin_b.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção C',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha ao queixo do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/chin_c.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção D',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha ao queixo do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/chin_d.png',
|
||||
title: 'Não',
|
||||
description: 'O queixo não se assemelha à imagem',
|
||||
weight: 1,
|
||||
value: 'nao',
|
||||
),
|
||||
],
|
||||
currentScore: currentScore,
|
||||
nextRoute: (context, nextScore) => MaterialPageRoute<void>(
|
||||
builder: (_) => Quiz5Screen(currentScore: nextScore, scopeId: scopeId),
|
||||
),
|
||||
answerType: QuizAnswerType.image,
|
||||
answerType: QuizAnswerType.yesNo,
|
||||
showBackButton: true,
|
||||
);
|
||||
}
|
||||
@@ -272,43 +218,29 @@ class Quiz7Screen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return QuizQuestionScreen(
|
||||
title: 'Quiz 7/26',
|
||||
question:
|
||||
'Qual das seguintes imagens se assemelha à boca do seu filho/a?',
|
||||
question: 'A boca do seu filho/a se parece com a desta imagem?',
|
||||
questionImagePaths: const ['assets/mockup_images/14.jpeg'],
|
||||
suggestedYoutubeId: '', // TODO: colar o ID do YouTube do Episódio 5
|
||||
suggestedVideoTitle: 'Ver vídeo: Episódio 5',
|
||||
answers: const [
|
||||
QuizAnswer(
|
||||
title: 'Opção A',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à boca do seu filho/a',
|
||||
title: 'Sim',
|
||||
description: 'A boca se assemelha à imagem',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/mouth2_a.png',
|
||||
value: 'sim',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção B',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à boca do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/mouth2_b.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção C',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à boca do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/mouth2_c.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção D',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha à boca do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/mouth2_d.png',
|
||||
title: 'Não',
|
||||
description: 'A boca não se assemelha à imagem',
|
||||
weight: 1,
|
||||
value: 'nao',
|
||||
),
|
||||
],
|
||||
currentScore: currentScore,
|
||||
nextRoute: (context, nextScore) => MaterialPageRoute<void>(
|
||||
builder: (_) => Quiz8Screen(currentScore: nextScore, scopeId: scopeId),
|
||||
),
|
||||
answerType: QuizAnswerType.image,
|
||||
answerType: QuizAnswerType.yesNo,
|
||||
showBackButton: true,
|
||||
);
|
||||
}
|
||||
@@ -326,42 +258,29 @@ class Quiz8Screen extends StatelessWidget {
|
||||
return QuizQuestionScreen(
|
||||
title: 'Quiz 8/26',
|
||||
question:
|
||||
'Qual das seguintes imagens se assemelha ao freio do seu filho/a?',
|
||||
'O frénulo (freio) da língua do seu filho/a se parece com o desta imagem?',
|
||||
questionImagePaths: const ['assets/mockup_images/17.png'],
|
||||
suggestedYoutubeId: '', // TODO: colar o ID do YouTube do Episódio 6
|
||||
suggestedVideoTitle: 'Ver vídeo: Episódio 6',
|
||||
answers: const [
|
||||
QuizAnswer(
|
||||
title: 'Opção A',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha ao freio do seu filho/a',
|
||||
title: 'Sim',
|
||||
description: 'O frénulo se assemelha à imagem',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/frenulum_a.png',
|
||||
value: 'sim',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção B',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha ao freio do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/frenulum_b.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção C',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha ao freio do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/frenulum_c.png',
|
||||
),
|
||||
QuizAnswer(
|
||||
title: 'Opção D',
|
||||
description:
|
||||
'Selecione se a imagem se assemelha ao freio do seu filho/a',
|
||||
weight: 2,
|
||||
imagePath: 'assets/images/frenulum_d.png',
|
||||
title: 'Não',
|
||||
description: 'O frénulo não se assemelha à imagem',
|
||||
weight: 1,
|
||||
value: 'nao',
|
||||
),
|
||||
],
|
||||
currentScore: currentScore,
|
||||
nextRoute: (context, nextScore) => MaterialPageRoute<void>(
|
||||
builder: (_) => Quiz9Screen(currentScore: nextScore, scopeId: scopeId),
|
||||
),
|
||||
answerType: QuizAnswerType.image,
|
||||
answerType: QuizAnswerType.yesNo,
|
||||
showBackButton: true,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
|
||||
import '../screens/video_screen.dart';
|
||||
|
||||
typedef QuizNextBuilder =
|
||||
Route<void> Function(BuildContext context, int nextScore);
|
||||
|
||||
@@ -37,6 +39,9 @@ class QuizQuestionScreen extends StatefulWidget {
|
||||
this.showBackButton = false,
|
||||
this.answerType = QuizAnswerType.text,
|
||||
this.questionImagePaths = const [],
|
||||
this.suggestedVideoPath,
|
||||
this.suggestedYoutubeId,
|
||||
this.suggestedVideoTitle,
|
||||
});
|
||||
|
||||
final String title;
|
||||
@@ -49,6 +54,9 @@ class QuizQuestionScreen extends StatefulWidget {
|
||||
final bool showBackButton;
|
||||
final QuizAnswerType answerType;
|
||||
final List<String> questionImagePaths;
|
||||
final String? suggestedVideoPath;
|
||||
final String? suggestedYoutubeId;
|
||||
final String? suggestedVideoTitle;
|
||||
|
||||
@override
|
||||
State<QuizQuestionScreen> createState() => _QuizQuestionScreenState();
|
||||
@@ -58,6 +66,7 @@ class _QuizQuestionScreenState extends State<QuizQuestionScreen> {
|
||||
int? _selected;
|
||||
TextEditingController? _numberController;
|
||||
int? _numberValue;
|
||||
bool _navigating = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -76,9 +85,9 @@ class _QuizQuestionScreenState extends State<QuizQuestionScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
bool canProceed = _selected != null;
|
||||
bool canProceed = _selected != null && !_navigating;
|
||||
if (widget.answerType == QuizAnswerType.number) {
|
||||
canProceed = _numberValue != null && _numberValue! >= 0;
|
||||
canProceed = _numberValue != null && _numberValue! >= 0 && !_navigating;
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
@@ -145,6 +154,35 @@ class _QuizQuestionScreenState extends State<QuizQuestionScreen> {
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
if (widget.suggestedVideoPath != null ||
|
||||
widget.suggestedYoutubeId != null) ...[
|
||||
TextButton.icon(
|
||||
onPressed: () => showVideoPlayerDialog(
|
||||
context,
|
||||
VideoData(
|
||||
id: 0,
|
||||
title:
|
||||
widget.suggestedVideoTitle ?? 'Vídeo',
|
||||
description: '',
|
||||
videoPath: widget.suggestedVideoPath,
|
||||
youtubeId: widget.suggestedYoutubeId,
|
||||
),
|
||||
),
|
||||
icon: const Icon(
|
||||
Icons.play_circle_outline_rounded,
|
||||
color: Color(0xFF2F9E94),
|
||||
),
|
||||
label: Text(
|
||||
widget.suggestedVideoTitle ??
|
||||
'Ver vídeo (opcional)',
|
||||
style: const TextStyle(
|
||||
color: Color(0xFF2F9E94),
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
],
|
||||
Text(
|
||||
widget.question,
|
||||
textAlign: TextAlign.center,
|
||||
@@ -239,6 +277,7 @@ class _QuizQuestionScreenState extends State<QuizQuestionScreen> {
|
||||
onPressed: !canProceed
|
||||
? null
|
||||
: () {
|
||||
setState(() => _navigating = true);
|
||||
int nextScore = widget.currentScore;
|
||||
if (widget.answerType ==
|
||||
QuizAnswerType.number) {
|
||||
@@ -454,7 +493,7 @@ class _QuizAnswerTile extends StatelessWidget {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
if (answer.imagePath != null) ...[
|
||||
ClipRRect(
|
||||
@@ -478,19 +517,14 @@ class _QuizAnswerTile extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
answer.title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 15,
|
||||
color: Color(0xFF2F9E94),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
Text(
|
||||
answer.title,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 15,
|
||||
color: Color(0xFF2F9E94),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -516,6 +550,7 @@ class _QuestionReferenceImages extends StatelessWidget {
|
||||
child: Image.asset(
|
||||
paths.first,
|
||||
fit: BoxFit.cover,
|
||||
cacheWidth: 800,
|
||||
errorBuilder: (context, error, stackTrace) => _placeholder(),
|
||||
),
|
||||
),
|
||||
@@ -534,6 +569,7 @@ class _QuestionReferenceImages extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Image.asset(
|
||||
paths[i],
|
||||
cacheWidth: 300,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) => _placeholder(),
|
||||
),
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import '../main.dart' show supabase;
|
||||
import 'quiz_prefs.dart';
|
||||
|
||||
class QuizResultScreen extends StatefulWidget {
|
||||
@@ -40,7 +39,7 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
|
||||
maxScore: widget.maxScore,
|
||||
);
|
||||
} else {
|
||||
final uid = FirebaseAuth.instance.currentUser?.uid;
|
||||
final uid = supabase.auth.currentUser?.id;
|
||||
if (uid != null && uid.trim().isNotEmpty) {
|
||||
await QuizPrefs.saveLastResultForUser(
|
||||
userId: uid,
|
||||
@@ -55,25 +54,23 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
final uid = FirebaseAuth.instance.currentUser?.uid;
|
||||
final uid = supabase.auth.currentUser?.id;
|
||||
final userId = (uid ?? '').trim();
|
||||
if (userId.isNotEmpty &&
|
||||
scope.isNotEmpty &&
|
||||
scope.startsWith('${userId}_')) {
|
||||
final childId = scope.substring(userId.length + 1).trim();
|
||||
if (childId.isNotEmpty) {
|
||||
// Fire-and-forget: avoid blocking UI on Firestore (may hang offline).
|
||||
// Fire-and-forget: avoid blocking UI on erros de rede.
|
||||
unawaited(
|
||||
FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(userId)
|
||||
.collection('children')
|
||||
.doc(childId)
|
||||
.set({
|
||||
'lastScore': widget.finalScore,
|
||||
'lastMaxScore': widget.maxScore,
|
||||
'lastQuizAt': FieldValue.serverTimestamp(),
|
||||
}, SetOptions(merge: true))
|
||||
supabase
|
||||
.from('children')
|
||||
.update({
|
||||
'last_score': widget.finalScore,
|
||||
'last_max_score': widget.maxScore,
|
||||
'last_quiz_at': DateTime.now().toIso8601String(),
|
||||
})
|
||||
.eq('id', childId)
|
||||
.catchError((_) {}),
|
||||
);
|
||||
}
|
||||
|
||||
212
lib/screens/settings_screen.dart
Normal file
212
lib/screens/settings_screen.dart
Normal file
@@ -0,0 +1,212 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../main.dart' show supabase;
|
||||
import '../widgets/app_dialogs.dart';
|
||||
import 'terms_screen.dart';
|
||||
|
||||
const Color _teal = Color(0xFF2F9E94);
|
||||
const Color _accentPink = Color(0xFFFF55A7);
|
||||
|
||||
/// Conteúdo da aba de Configurações, para ser embutido na bottom navigation
|
||||
/// do LoggedHomeScreen (sem Scaffold/AppBar próprios).
|
||||
class SettingsBody extends StatefulWidget {
|
||||
const SettingsBody({super.key});
|
||||
|
||||
@override
|
||||
State<SettingsBody> createState() => _SettingsBodyState();
|
||||
}
|
||||
|
||||
class _SettingsBodyState extends State<SettingsBody> {
|
||||
bool _deletingAccount = false;
|
||||
|
||||
Future<void> _signOut() async {
|
||||
await supabase.auth.signOut();
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
}
|
||||
|
||||
Future<void> _confirmDeleteAccountData() async {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
final confirmed = await showConfirmDialog(
|
||||
context,
|
||||
title: 'Apagar dados da conta',
|
||||
message:
|
||||
'Isso remove permanentemente seu perfil, crianças cadastradas e '
|
||||
'fotos. Essa ação não pode ser desfeita. Deseja continuar?',
|
||||
confirmLabel: 'Apagar',
|
||||
confirmColor: _accentPink,
|
||||
);
|
||||
|
||||
if (confirmed != true) return;
|
||||
|
||||
final uid = supabase.auth.currentUser?.id;
|
||||
if (uid == null) return;
|
||||
|
||||
setState(() => _deletingAccount = true);
|
||||
try {
|
||||
await supabase.from('children').delete().eq('owner_id', uid);
|
||||
await supabase.from('profiles').delete().eq('id', uid);
|
||||
await supabase.auth.signOut();
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(SnackBar(content: Text('Erro ao apagar: $e')));
|
||||
} finally {
|
||||
if (mounted) setState(() => _deletingAccount = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = supabase.auth.currentUser;
|
||||
final name = (user?.userMetadata?['name'] ?? '').toString().trim();
|
||||
final email = (user?.email ?? '').trim();
|
||||
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
_SectionLabel('Conta'),
|
||||
_SettingsCard(
|
||||
children: [
|
||||
_InfoTile(
|
||||
icon: Icons.person_outline_rounded,
|
||||
title: name.isEmpty ? 'Sem nome' : name,
|
||||
subtitle: email,
|
||||
),
|
||||
const Divider(height: 1),
|
||||
_ActionTile(
|
||||
icon: Icons.logout_rounded,
|
||||
title: 'Sair',
|
||||
onTap: _signOut,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_SectionLabel('Sobre'),
|
||||
_SettingsCard(
|
||||
children: [
|
||||
_ActionTile(
|
||||
icon: Icons.description_outlined,
|
||||
title: 'Termos de Serviço',
|
||||
onTap: () => Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(builder: (_) => const TermsScreen()),
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
const _InfoTile(
|
||||
icon: Icons.info_outline_rounded,
|
||||
title: 'Versão do app',
|
||||
subtitle: '1.0.0',
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_SectionLabel('Zona de risco'),
|
||||
_SettingsCard(
|
||||
children: [
|
||||
_ActionTile(
|
||||
icon: Icons.delete_forever_rounded,
|
||||
title: 'Apagar dados da conta',
|
||||
titleColor: _accentPink,
|
||||
loading: _deletingAccount,
|
||||
onTap: _deletingAccount ? null : _confirmDeleteAccountData,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionLabel extends StatelessWidget {
|
||||
const _SectionLabel(this.text);
|
||||
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 4, bottom: 8),
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
color: _teal,
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SettingsCard extends StatelessWidget {
|
||||
const _SettingsCard({required this.children});
|
||||
|
||||
final List<Widget> children;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
elevation: 6,
|
||||
shadowColor: Colors.black.withValues(alpha: 0.12),
|
||||
child: Column(children: children),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InfoTile extends StatelessWidget {
|
||||
const _InfoTile({required this.icon, required this.title, this.subtitle});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String? subtitle;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Icon(icon, color: _teal),
|
||||
title: Text(title, style: const TextStyle(fontWeight: FontWeight.w800)),
|
||||
subtitle: (subtitle == null || subtitle!.isEmpty)
|
||||
? null
|
||||
: Text(subtitle!),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ActionTile extends StatelessWidget {
|
||||
const _ActionTile({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.onTap,
|
||||
this.titleColor,
|
||||
this.loading = false,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final VoidCallback? onTap;
|
||||
final Color? titleColor;
|
||||
final bool loading;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
leading: Icon(icon, color: titleColor ?? _teal),
|
||||
title: Text(
|
||||
title,
|
||||
style: TextStyle(fontWeight: FontWeight.w800, color: titleColor),
|
||||
),
|
||||
trailing: loading
|
||||
? const SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.chevron_right_rounded),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
}
|
||||
72
lib/screens/terms_screen.dart
Normal file
72
lib/screens/terms_screen.dart
Normal file
@@ -0,0 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TermsScreen extends StatelessWidget {
|
||||
const TermsScreen({super.key});
|
||||
|
||||
static const Color _teal = Color(0xFF2F9E94);
|
||||
static const Color _accentPink = Color(0xFFFF55A7);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: _teal,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
title: const Text(
|
||||
'Termos de Serviço',
|
||||
style: TextStyle(fontWeight: FontWeight.w900),
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFFFE6F1), Color(0xFFFFC9DF)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
'Termos de Serviço',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w900,
|
||||
color: _accentPink,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(18),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.85),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: const SingleChildScrollView(
|
||||
child: Text(
|
||||
'Conteúdo dos Termos de Serviço em breve.\n\n'
|
||||
'Este espaço será preenchido com os termos de uso e '
|
||||
'condições do Check-Teeth Kids.',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
height: 1.5,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,24 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
import 'package:youtube_player_flutter/youtube_player_flutter.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
|
||||
// cada vídeo. Episódios 8-13 continuam embutidos no app (assets/videos).
|
||||
class VideoData {
|
||||
final int id;
|
||||
final String title;
|
||||
final String description;
|
||||
final String videoPath;
|
||||
final String? videoPath;
|
||||
final String? youtubeId;
|
||||
|
||||
VideoData({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.videoPath,
|
||||
this.videoPath,
|
||||
this.youtubeId,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,43 +31,43 @@ final List<VideoData> videoList = [
|
||||
id: 1,
|
||||
title: 'Episódio 1',
|
||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||
videoPath: 'assets/videos/episodio_01.mp4',
|
||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
||||
),
|
||||
VideoData(
|
||||
id: 2,
|
||||
title: 'Episódio 2',
|
||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||
videoPath: 'assets/videos/episodio_02.mp4',
|
||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
||||
),
|
||||
VideoData(
|
||||
id: 3,
|
||||
title: 'Episódio 3',
|
||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||
videoPath: 'assets/videos/episodio_03.mp4',
|
||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
||||
),
|
||||
VideoData(
|
||||
id: 4,
|
||||
title: 'Episódio 4',
|
||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||
videoPath: 'assets/videos/episodio_04.mp4',
|
||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
||||
),
|
||||
VideoData(
|
||||
id: 5,
|
||||
title: 'Episódio 5',
|
||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||
videoPath: 'assets/videos/episodio_05.mp4',
|
||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
||||
),
|
||||
VideoData(
|
||||
id: 6,
|
||||
title: 'Episódio 6',
|
||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||
videoPath: 'assets/videos/episodio_06.mp4',
|
||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
||||
),
|
||||
VideoData(
|
||||
id: 7,
|
||||
title: 'Episódio 7',
|
||||
description: 'Aprenda sobre saúde bucal neste episódio',
|
||||
videoPath: 'assets/videos/episodio_07.mp4',
|
||||
youtubeId: '', // TODO: colar o ID do vídeo do YouTube (não listado)
|
||||
),
|
||||
VideoData(
|
||||
id: 8,
|
||||
@@ -105,6 +110,25 @@ final List<VideoData> videoList = [
|
||||
// Cache for video controllers to avoid re-initializing
|
||||
final Map<String, VideoPlayerController> _videoControllerCache = {};
|
||||
|
||||
Future<void> showVideoPlayerDialog(BuildContext context, VideoData video) {
|
||||
if (video.youtubeId != null) {
|
||||
if (video.youtubeId!.isEmpty) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('Vídeo ainda não disponível')));
|
||||
return Future.value();
|
||||
}
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => _YoutubePlayerDialog(video: video),
|
||||
);
|
||||
}
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => _VideoPlayerDialog(video: video),
|
||||
);
|
||||
}
|
||||
|
||||
class VideoScreen extends StatefulWidget {
|
||||
const VideoScreen({super.key});
|
||||
|
||||
@@ -268,29 +292,41 @@ class _VideoScreenState extends State<VideoScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
class _VideoButton extends StatefulWidget {
|
||||
const _VideoButton({required this.video});
|
||||
/// Preview de um vídeo (frame local ou thumbnail do YouTube), reutilizável
|
||||
/// em qualquer card que precise mostrar "a cara" de um episódio.
|
||||
class VideoThumbnail extends StatefulWidget {
|
||||
const VideoThumbnail({
|
||||
super.key,
|
||||
required this.video,
|
||||
this.borderRadius = 12,
|
||||
this.iconSize = 48,
|
||||
});
|
||||
|
||||
final VideoData video;
|
||||
final double borderRadius;
|
||||
final double iconSize;
|
||||
|
||||
@override
|
||||
State<_VideoButton> createState() => _VideoButtonState();
|
||||
State<VideoThumbnail> createState() => _VideoThumbnailState();
|
||||
}
|
||||
|
||||
class _VideoButtonState extends State<_VideoButton> {
|
||||
class _VideoThumbnailState extends State<VideoThumbnail> {
|
||||
VideoPlayerController? _controller;
|
||||
bool _isInitialized = false;
|
||||
|
||||
bool get _isYoutube => widget.video.youtubeId != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initializeVideo();
|
||||
if (!_isYoutube) _initializeVideo();
|
||||
}
|
||||
|
||||
Future<void> _initializeVideo() async {
|
||||
final path = widget.video.videoPath!;
|
||||
// Check if controller exists in cache
|
||||
if (_videoControllerCache.containsKey(widget.video.videoPath)) {
|
||||
_controller = _videoControllerCache[widget.video.videoPath];
|
||||
if (_videoControllerCache.containsKey(path)) {
|
||||
_controller = _videoControllerCache[path];
|
||||
await _controller!.seekTo(const Duration(seconds: 2));
|
||||
await _controller!.pause();
|
||||
if (mounted) {
|
||||
@@ -302,12 +338,12 @@ class _VideoButtonState extends State<_VideoButton> {
|
||||
}
|
||||
|
||||
// Create new controller and cache it
|
||||
_controller = VideoPlayerController.asset(widget.video.videoPath);
|
||||
_controller = VideoPlayerController.asset(path);
|
||||
try {
|
||||
await _controller!.initialize();
|
||||
await _controller!.seekTo(const Duration(seconds: 2));
|
||||
await _controller!.pause();
|
||||
_videoControllerCache[widget.video.videoPath] = _controller!;
|
||||
_videoControllerCache[path] = _controller!;
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isInitialized = true;
|
||||
@@ -332,6 +368,73 @@ class _VideoButtonState extends State<_VideoButton> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_isYoutube) {
|
||||
final youtubeId = widget.video.youtubeId!;
|
||||
if (youtubeId.isEmpty) {
|
||||
return Center(
|
||||
child: Icon(
|
||||
Icons.hourglass_top_rounded,
|
||||
size: widget.iconSize * 0.85,
|
||||
color: Colors.black26,
|
||||
),
|
||||
);
|
||||
}
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
child: Image.network(
|
||||
'https://img.youtube.com/vi/$youtubeId/hqdefault.jpg',
|
||||
fit: BoxFit.cover,
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
errorBuilder: (context, error, stackTrace) => Center(
|
||||
child: Icon(
|
||||
Icons.play_circle_fill_rounded,
|
||||
size: widget.iconSize,
|
||||
color: VideoScreen._accentPink,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return _isInitialized && _controller != null
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(widget.borderRadius),
|
||||
child: FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
child: SizedBox(
|
||||
width: _controller!.value.size.width,
|
||||
height: _controller!.value.size.height,
|
||||
child: VideoPlayer(_controller!),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Center(
|
||||
child: Icon(
|
||||
Icons.play_circle_fill_rounded,
|
||||
size: widget.iconSize,
|
||||
color: VideoScreen._accentPink,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _VideoButton extends StatelessWidget {
|
||||
const _VideoButton({required this.video});
|
||||
|
||||
final VideoData video;
|
||||
|
||||
void _showVideoPlayer(BuildContext context, VideoData video) {
|
||||
if (video.youtubeId == null &&
|
||||
_videoControllerCache.containsKey(video.videoPath)) {
|
||||
// Dispose the cached controller to avoid codec conflict with dialog controller
|
||||
_videoControllerCache[video.videoPath]!.dispose();
|
||||
_videoControllerCache.remove(video.videoPath);
|
||||
}
|
||||
showVideoPlayerDialog(context, video);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
@@ -341,7 +444,7 @@ class _VideoButtonState extends State<_VideoButton> {
|
||||
color: Colors.white,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
onTap: () => _showVideoPlayer(context, widget.video),
|
||||
onTap: () => _showVideoPlayer(context, video),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
@@ -353,29 +456,11 @@ class _VideoButtonState extends State<_VideoButton> {
|
||||
color: const Color(0xFFFFE6F1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: _isInitialized && _controller != null
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
child: SizedBox(
|
||||
width: _controller!.value.size.width,
|
||||
height: _controller!.value.size.height,
|
||||
child: VideoPlayer(_controller!),
|
||||
),
|
||||
),
|
||||
)
|
||||
: const Center(
|
||||
child: Icon(
|
||||
Icons.play_circle_fill_rounded,
|
||||
size: 48,
|
||||
color: VideoScreen._accentPink,
|
||||
),
|
||||
),
|
||||
child: VideoThumbnail(video: video),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
widget.video.title,
|
||||
video.title,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 14,
|
||||
@@ -386,7 +471,7 @@ class _VideoButtonState extends State<_VideoButton> {
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
widget.video.description,
|
||||
video.description,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
@@ -401,17 +486,69 @@ class _VideoButtonState extends State<_VideoButton> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _showVideoPlayer(BuildContext context, VideoData video) {
|
||||
// Dispose the cached controller to avoid codec conflict with dialog controller
|
||||
if (_videoControllerCache.containsKey(video.videoPath)) {
|
||||
_videoControllerCache[video.videoPath]!.dispose();
|
||||
_videoControllerCache.remove(video.videoPath);
|
||||
}
|
||||
_controller = null;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => _VideoPlayerDialog(video: video),
|
||||
class _YoutubePlayerDialog extends StatefulWidget {
|
||||
const _YoutubePlayerDialog({required this.video});
|
||||
|
||||
final VideoData video;
|
||||
|
||||
@override
|
||||
State<_YoutubePlayerDialog> createState() => _YoutubePlayerDialogState();
|
||||
}
|
||||
|
||||
class _YoutubePlayerDialogState extends State<_YoutubePlayerDialog> {
|
||||
late final YoutubePlayerController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = YoutubePlayerController(
|
||||
initialVideoId: widget.video.youtubeId!,
|
||||
flags: const YoutubePlayerFlags(autoPlay: true, mute: false),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
return Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
insetPadding: const EdgeInsets.all(16),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: VideoScreen._accentPink.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
border: Border.all(color: VideoScreen._accentPink, width: 3),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(21),
|
||||
child: SizedBox(
|
||||
width: size.width * 0.9,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
YoutubePlayer(controller: _controller),
|
||||
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(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -436,7 +573,7 @@ class _VideoPlayerDialogState extends State<_VideoPlayerDialog> {
|
||||
}
|
||||
|
||||
Future<void> _initializeVideo() async {
|
||||
_controller = VideoPlayerController.asset(widget.video.videoPath);
|
||||
_controller = VideoPlayerController.asset(widget.video.videoPath!);
|
||||
try {
|
||||
await _controller.initialize();
|
||||
if (mounted) {
|
||||
@@ -502,7 +639,7 @@ class _VideoPlayerDialogState extends State<_VideoPlayerDialog> {
|
||||
if (_isInitialized)
|
||||
_VideoControls(
|
||||
controller: _controller,
|
||||
videoPath: widget.video.videoPath,
|
||||
videoPath: widget.video.videoPath!,
|
||||
onClose: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
|
||||
46
lib/widgets/app_dialogs.dart
Normal file
46
lib/widgets/app_dialogs.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
const Color _teal = Color(0xFF2F9E94);
|
||||
const Color _accentPink = Color(0xFFFF55A7);
|
||||
|
||||
/// Diálogo de confirmação com a identidade visual do app (título rosa,
|
||||
/// botões em pílula), usado para todas as confirmações destrutivas/decisórias.
|
||||
Future<bool?> showConfirmDialog(
|
||||
BuildContext context, {
|
||||
required String title,
|
||||
String? message,
|
||||
String cancelLabel = 'Cancelar',
|
||||
required String confirmLabel,
|
||||
Color confirmColor = _teal,
|
||||
}) {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
title: Text(
|
||||
title,
|
||||
style: const TextStyle(fontWeight: FontWeight.w900, color: _accentPink),
|
||||
),
|
||||
content: message == null ? null : Text(message),
|
||||
actions: [
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(foregroundColor: _teal),
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: Text(cancelLabel),
|
||||
),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: confirmColor,
|
||||
foregroundColor: Colors.white,
|
||||
shape: const StadiumBorder(),
|
||||
textStyle: const TextStyle(fontWeight: FontWeight.w800),
|
||||
),
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: Text(confirmLabel),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user