From fd0705ad46f55199a12912afef1ac435fc0ef3a3 Mon Sep 17 00:00:00 2001 From: TammiLion Date: Mon, 21 Oct 2024 11:21:18 +0200 Subject: [PATCH] Fix question timer not resetting when there's only one reporter. --- .../reflect/bloc/interview_cubit.dart | 1 + .../presentation/models/interview_custom.dart | 6 + .../presentation/pages/interview_screen.dart | 2 + .../pages/record_answer_screen.dart | 131 ++++++++++-------- 4 files changed, 83 insertions(+), 57 deletions(-) diff --git a/lib/features/family/features/reflect/bloc/interview_cubit.dart b/lib/features/family/features/reflect/bloc/interview_cubit.dart index e09527434..b7681fa6f 100644 --- a/lib/features/family/features/reflect/bloc/interview_cubit.dart +++ b/lib/features/family/features/reflect/bloc/interview_cubit.dart @@ -68,6 +68,7 @@ class InterviewCubit extends CommonCubit { return; } else { if (!_hasOnlyOneReporter()) _showPassThePhoneScreen = true; + if (_hasOnlyOneReporter()) emitCustom(const InterviewCustom.resetTimer()); if (_currentReporterIndex < _reporters.length - 1) { _currentReporterIndex++; } else { diff --git a/lib/features/family/features/reflect/presentation/models/interview_custom.dart b/lib/features/family/features/reflect/presentation/models/interview_custom.dart index 7233b9aad..44498c21f 100644 --- a/lib/features/family/features/reflect/presentation/models/interview_custom.dart +++ b/lib/features/family/features/reflect/presentation/models/interview_custom.dart @@ -8,6 +8,12 @@ sealed class InterviewCustom { const factory InterviewCustom.goToGratitudeSelection( {required GameProfile reporter}) = GratitudeSelection; + + const factory InterviewCustom.resetTimer() = ResetTimer; +} + +class ResetTimer extends InterviewCustom { + const ResetTimer(); } class PassThePhoneToSidekick extends InterviewCustom { diff --git a/lib/features/family/features/reflect/presentation/pages/interview_screen.dart b/lib/features/family/features/reflect/presentation/pages/interview_screen.dart index 2040bc936..bd5c9641d 100644 --- a/lib/features/family/features/reflect/presentation/pages/interview_screen.dart +++ b/lib/features/family/features/reflect/presentation/pages/interview_screen.dart @@ -59,6 +59,8 @@ class _InterviewScreenState extends State { Navigator.of(context).pushReplacement( GratitudeSelectionScreen(reporter: data.reporter).toRoute(context), ); + case ResetTimer(): + //do nothing here } } } diff --git a/lib/features/family/features/reflect/presentation/pages/record_answer_screen.dart b/lib/features/family/features/reflect/presentation/pages/record_answer_screen.dart index 2d4ca0cee..fd61d1804 100644 --- a/lib/features/family/features/reflect/presentation/pages/record_answer_screen.dart +++ b/lib/features/family/features/reflect/presentation/pages/record_answer_screen.dart @@ -1,18 +1,21 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/svg.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:givt_app/app/injection/injection.dart'; import 'package:givt_app/core/config/app_config.dart'; import 'package:givt_app/core/enums/amplitude_events.dart'; import 'package:givt_app/features/family/features/reflect/bloc/interview_cubit.dart'; +import 'package:givt_app/features/family/features/reflect/presentation/models/interview_custom.dart'; import 'package:givt_app/features/family/features/reflect/presentation/models/interview_uimodel.dart'; import 'package:givt_app/features/family/features/reflect/presentation/widgets/leave_game_button.dart'; import 'package:givt_app/features/family/features/reflect/presentation/widgets/record_timer.dart'; import 'package:givt_app/features/family/helpers/vibrator.dart'; import 'package:givt_app/features/family/shared/design/components/components.dart'; import 'package:givt_app/features/family/shared/widgets/texts/shared_texts.dart'; +import 'package:givt_app/shared/bloc/base_state.dart'; import 'package:givt_app/shared/models/analytics_event.dart'; import 'package:givt_app/shared/widgets/fun_scaffold.dart'; import 'package:givt_app/utils/app_theme.dart'; @@ -28,8 +31,10 @@ class RecordAnswerScreen extends StatefulWidget { } class _RecordAnswerScreenState extends State { - _RecordAnswerScreenState({int startSeconds = 60}) - : _remainingSeconds = startSeconds; + _RecordAnswerScreenState() : _remainingSeconds = startSeconds; + + static const int startSeconds = 60; + Timer? _timer; int _remainingSeconds; InterviewCubit cubit = getIt(); @@ -94,71 +99,83 @@ class _RecordAnswerScreenState extends State { super.dispose(); } + void _resetTimer() { + _remainingSeconds = startSeconds; + } + @override Widget build(BuildContext context) { - return FunScaffold( - canPop: false, - appBar: FunTopAppBar.primary99( - title: widget.uiModel.reporter.firstName!, - leading: Padding( - padding: const EdgeInsets.all(8), - child: SvgPicture.network( - widget.uiModel.reporter.pictureURL!, - width: 36, - height: 36, - ), - ), - actions: const [ - LeaveGameButton(), - ], - ), - body: Column( - children: [ - const Spacer(), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 24), - child: TitleMediumText( - widget.uiModel.question, - textAlign: TextAlign.center, + return BlocListener( + bloc: cubit, + listener: (BuildContext context, state) { + if (state is CustomState && state.custom is ResetTimer) { + _resetTimer(); + } + }, + child: FunScaffold( + canPop: false, + appBar: FunTopAppBar.primary99( + title: widget.uiModel.reporter.firstName!, + leading: Padding( + padding: const EdgeInsets.all(8), + child: SvgPicture.network( + widget.uiModel.reporter.pictureURL!, + width: 36, + height: 36, ), ), - const Spacer(), - Container( - decoration: BoxDecoration( - border: Border.all( - color: AppTheme.generosityChallangeCardBorder, - width: 2, + actions: const [ + LeaveGameButton(), + ], + ), + body: Column( + children: [ + const Spacer(), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 24), + child: TitleMediumText( + widget.uiModel.question, + textAlign: TextAlign.center, ), - borderRadius: BorderRadius.circular(20), - color: AppTheme.generosityChallangeCardBackground, ), - child: Column( - children: [ - const SizedBox(height: 16), - RecordTimerWidget( - seconds: _displaySeconds(), - minutes: _displayMinutes(), - showRedVersion: _isLastTenSeconds(), + const Spacer(), + Container( + decoration: BoxDecoration( + border: Border.all( + color: AppTheme.generosityChallangeCardBorder, + width: 2, ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 24), - child: FunButton( - rightIcon: FontAwesomeIcons.arrowRight, - onTap: () { - cubit.advanceToNext(); - }, - text: widget.uiModel.buttonText, - analyticsEvent: AnalyticsEvent( - AmplitudeEvents.reflectAndShareNextJournalistClicked, + borderRadius: BorderRadius.circular(20), + color: AppTheme.generosityChallangeCardBackground, + ), + child: Column( + children: [ + const SizedBox(height: 16), + RecordTimerWidget( + seconds: _displaySeconds(), + minutes: _displayMinutes(), + showRedVersion: _isLastTenSeconds(), + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 24), + child: FunButton( + rightIcon: FontAwesomeIcons.arrowRight, + onTap: () { + cubit.advanceToNext(); + }, + text: widget.uiModel.buttonText, + analyticsEvent: AnalyticsEvent( + AmplitudeEvents.reflectAndShareNextJournalistClicked, + ), ), ), - ), - const SizedBox(height: 24), - ], + const SizedBox(height: 24), + ], + ), ), - ), - const Spacer(), - ], + const Spacer(), + ], + ), ), ); }