Clinicas Parceiras e curiosidades retiradas.

This commit is contained in:
Carlos Correia
2026-05-22 11:10:49 +01:00
parent 4f57044196
commit ea009af0d3
6 changed files with 1809 additions and 1280 deletions

View File

@@ -6,7 +6,12 @@ import 'dart:async';
import 'quiz_prefs.dart';
class QuizResultScreen extends StatefulWidget {
const QuizResultScreen({super.key, required this.finalScore, required this.maxScore, this.scopeId});
const QuizResultScreen({
super.key,
required this.finalScore,
required this.maxScore,
this.scopeId,
});
final int finalScore;
final int maxScore;
@@ -17,39 +22,57 @@ class QuizResultScreen extends StatefulWidget {
}
class _QuizResultScreenState extends State<QuizResultScreen> {
late final Future<void> _saveResultFuture;
@override
void initState() {
super.initState();
_saveResultFuture = _saveResult();
}
Future<void> _saveResult() async {
QuizPrefs.markQuizSeen();
final scope = (widget.scopeId ?? '').trim();
if (scope.isNotEmpty) {
QuizPrefs.saveLastResultForScope(scopeId: scope, score: widget.finalScore, maxScore: widget.maxScore);
await QuizPrefs.saveLastResultForScope(
scopeId: scope,
score: widget.finalScore,
maxScore: widget.maxScore,
);
} else {
final uid = FirebaseAuth.instance.currentUser?.uid;
if (uid != null && uid.trim().isNotEmpty) {
QuizPrefs.saveLastResultForUser(userId: uid, score: widget.finalScore, maxScore: widget.maxScore);
await QuizPrefs.saveLastResultForUser(
userId: uid,
score: widget.finalScore,
maxScore: widget.maxScore,
);
} else {
QuizPrefs.saveLastResult(score: widget.finalScore, maxScore: widget.maxScore);
await QuizPrefs.saveLastResult(
score: widget.finalScore,
maxScore: widget.maxScore,
);
}
}
final uid = FirebaseAuth.instance.currentUser?.uid;
final userId = (uid ?? '').trim();
if (userId.isNotEmpty && scope.isNotEmpty && scope.startsWith('${userId}_')) {
if (userId.isNotEmpty &&
scope.isNotEmpty &&
scope.startsWith('${userId}_')) {
final childId = scope.substring(userId.length + 1).trim();
if (childId.isNotEmpty) {
unawaited(
FirebaseFirestore.instance
.collection('users')
.doc(userId)
.collection('children')
.doc(childId)
.set({
'lastScore': widget.finalScore,
'lastMaxScore': widget.maxScore,
'lastQuizAt': FieldValue.serverTimestamp(),
}, SetOptions(merge: true)).catchError((_) {}),
);
await FirebaseFirestore.instance
.collection('users')
.doc(userId)
.collection('children')
.doc(childId)
.set({
'lastScore': widget.finalScore,
'lastMaxScore': widget.maxScore,
'lastQuizAt': FieldValue.serverTimestamp(),
}, SetOptions(merge: true))
.catchError((_) {});
}
}
}
@@ -66,10 +89,7 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xFFFFE6F1),
Color(0xFFFFC9DF),
],
colors: [Color(0xFFFFE6F1), Color(0xFFFFC9DF)],
),
),
child: SafeArea(
@@ -84,7 +104,8 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () => Navigator.of(context).popUntil((r) => r.isFirst),
onPressed: () =>
Navigator.of(context).popUntil((r) => r.isFirst),
child: const Text(''),
),
),
@@ -118,8 +139,12 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
child: CircularProgressIndicator(
value: progress,
strokeWidth: 12,
backgroundColor: Colors.black.withValues(alpha: 0.10),
valueColor: const AlwaysStoppedAnimation(Color(0xFF2F9E94)),
backgroundColor: Colors.black
.withValues(alpha: 0.10),
valueColor:
const AlwaysStoppedAnimation(
Color(0xFF2F9E94),
),
),
),
Column(
@@ -137,7 +162,9 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
Text(
'${clamped.toInt()}/${widget.maxScore}',
style: TextStyle(
color: Colors.black.withValues(alpha: 0.60),
color: Colors.black.withValues(
alpha: 0.60,
),
fontWeight: FontWeight.w800,
),
),
@@ -171,7 +198,9 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
child: Text(
'Descarregar relatório (em breve)',
style: TextStyle(
color: const Color(0xFFFF55A7).withValues(alpha: 0.95),
color: const Color(
0xFFFF55A7,
).withValues(alpha: 0.95),
fontWeight: FontWeight.w800,
),
),
@@ -189,9 +218,12 @@ class _QuizResultScreenState extends State<QuizResultScreen> {
backgroundColor: const Color(0xFF2F9E94),
foregroundColor: Colors.white,
shape: const StadiumBorder(),
textStyle: const TextStyle(fontWeight: FontWeight.w900),
textStyle: const TextStyle(
fontWeight: FontWeight.w900,
),
),
onPressed: () => Navigator.of(context).popUntil((r) => r.isFirst),
onPressed: () =>
Navigator.of(context).popUntil((r) => r.isFirst),
child: const Text('Avançar'),
),
),