Skip to content

Commit

Permalink
Fix question timer not resetting when there's only one reporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
TammiLion committed Oct 21, 2024
1 parent 7fb51ae commit fd0705a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class InterviewCubit extends CommonCubit<InterviewUIModel, InterviewCustom> {
return;
} else {
if (!_hasOnlyOneReporter()) _showPassThePhoneScreen = true;
if (_hasOnlyOneReporter()) emitCustom(const InterviewCustom.resetTimer());
if (_currentReporterIndex < _reporters.length - 1) {
_currentReporterIndex++;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class _InterviewScreenState extends State<InterviewScreen> {
Navigator.of(context).pushReplacement(
GratitudeSelectionScreen(reporter: data.reporter).toRoute(context),
);
case ResetTimer():
//do nothing here
}
}
}
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -28,8 +31,10 @@ class RecordAnswerScreen extends StatefulWidget {
}

class _RecordAnswerScreenState extends State<RecordAnswerScreen> {
_RecordAnswerScreenState({int startSeconds = 60})
: _remainingSeconds = startSeconds;
_RecordAnswerScreenState() : _remainingSeconds = startSeconds;

static const int startSeconds = 60;

Timer? _timer;
int _remainingSeconds;
InterviewCubit cubit = getIt<InterviewCubit>();
Expand Down Expand Up @@ -94,71 +99,83 @@ class _RecordAnswerScreenState extends State<RecordAnswerScreen> {
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(),
],
),
),
);
}
Expand Down

0 comments on commit fd0705a

Please sign in to comment.