diff --git a/lib/features/children/generosity_challenge/cubit/generosity_challenge_cubit.dart b/lib/features/children/generosity_challenge/cubit/generosity_challenge_cubit.dart index c5a0a0690..3d308f22a 100644 --- a/lib/features/children/generosity_challenge/cubit/generosity_challenge_cubit.dart +++ b/lib/features/children/generosity_challenge/cubit/generosity_challenge_cubit.dart @@ -65,7 +65,11 @@ class GenerosityChallengeCubit extends Cubit { final lastCompletedDateTime = DateTime.parse(days[lastCompletedDayIndex].dateCompleted); final diff = lastCompletedDateTime.difference(DateTime.now()); - if (diff.inDays != 0) { + final timeDifference = + state.unlockDayTimeDifference == UnlockDayTimeDifference.days + ? diff.inDays + : diff.inMinutes; + if (timeDifference != 0) { return nextActiveDayIndex; } else { //no active day yet @@ -99,4 +103,14 @@ class GenerosityChallengeCubit extends Cubit { ), ); } + + Future toggleTimeDifference(int index) async { + final newTimeDifference = index == 0 + ? UnlockDayTimeDifference.days + : UnlockDayTimeDifference.minutes; + + emit(state.copyWith(unlockDayTimeDifference: newTimeDifference)); + final days = await _generosityChallengeRepository.loadFromCache(); + _refreshState(days); + } } diff --git a/lib/features/children/generosity_challenge/cubit/generosity_challenge_state.dart b/lib/features/children/generosity_challenge/cubit/generosity_challenge_state.dart index 889ee4540..80a78a555 100644 --- a/lib/features/children/generosity_challenge/cubit/generosity_challenge_state.dart +++ b/lib/features/children/generosity_challenge/cubit/generosity_challenge_state.dart @@ -8,9 +8,12 @@ enum GenerosityChallengeStatus { completed, } +enum UnlockDayTimeDifference { minutes, days } + class GenerosityChallengeState extends Equatable { const GenerosityChallengeState({ this.status = GenerosityChallengeStatus.initial, + this.unlockDayTimeDifference = UnlockDayTimeDifference.days, this.activeDayIndex = -1, this.detailedDayIndex = -1, this.days = const [], @@ -19,6 +22,7 @@ class GenerosityChallengeState extends Equatable { final List days; final int activeDayIndex; final int detailedDayIndex; + final UnlockDayTimeDifference unlockDayTimeDifference; final GenerosityChallengeStatus status; bool get hasActiveDay => activeDayIndex != -1; @@ -31,15 +35,19 @@ class GenerosityChallengeState extends Equatable { int? activeDayIndex, int? detailedDayIndex, GenerosityChallengeStatus? status, + UnlockDayTimeDifference? unlockDayTimeDifference, }) { return GenerosityChallengeState( days: days ?? this.days, activeDayIndex: activeDayIndex ?? this.activeDayIndex, detailedDayIndex: detailedDayIndex ?? this.detailedDayIndex, status: status ?? this.status, + unlockDayTimeDifference: + unlockDayTimeDifference ?? this.unlockDayTimeDifference, ); } @override - List get props => [days, activeDayIndex, detailedDayIndex, status]; + List get props => + [days, activeDayIndex, detailedDayIndex, status, unlockDayTimeDifference]; } diff --git a/lib/features/children/generosity_challenge/pages/generosity_challenge_overview.dart b/lib/features/children/generosity_challenge/pages/generosity_challenge_overview.dart index 6cde983ad..5d7e1a75e 100644 --- a/lib/features/children/generosity_challenge/pages/generosity_challenge_overview.dart +++ b/lib/features/children/generosity_challenge/pages/generosity_challenge_overview.dart @@ -8,10 +8,25 @@ import 'package:givt_app/features/children/generosity_challenge/utils/generosity import 'package:givt_app/features/children/generosity_challenge/widgets/day_button.dart'; import 'package:givt_app/features/children/generosity_challenge/widgets/generosity_app_bar.dart'; import 'package:givt_app/utils/utils.dart'; +import 'package:package_info_plus/package_info_plus.dart'; -class GenerosityChallengeOverview extends StatelessWidget { +class GenerosityChallengeOverview extends StatefulWidget { const GenerosityChallengeOverview({super.key}); + @override + State createState() => + _GenerosityChallengeOverviewState(); +} + +class _GenerosityChallengeOverviewState + extends State { + bool isDebug = false; + @override + void initState() { + super.initState(); + _isDebug().then((value) => isDebug = value); + } + @override Widget build(BuildContext context) { final challenge = context.watch(); @@ -69,6 +84,30 @@ class GenerosityChallengeOverview extends StatelessWidget { ); }, ), + const Spacer(), + if (isDebug) + ToggleButtons( + borderRadius: const BorderRadius.all(Radius.circular(8)), + selectedBorderColor: Colors.blue[700], + selectedColor: Colors.white, + fillColor: Colors.blue[200], + color: Colors.blue[400], + constraints: const BoxConstraints( + minHeight: 40, + minWidth: 80, + ), + isSelected: [ + challenge.state.unlockDayTimeDifference == + UnlockDayTimeDifference.days, + challenge.state.unlockDayTimeDifference == + UnlockDayTimeDifference.minutes, + ], + onPressed: challenge.toggleTimeDifference, + children: [ + Text(UnlockDayTimeDifference.days.name), + Text(UnlockDayTimeDifference.minutes.name), + ], + ), ], ), ], @@ -77,6 +116,11 @@ class GenerosityChallengeOverview extends StatelessWidget { ); } + Future _isDebug() async { + final info = await PackageInfo.fromPlatform(); + return info.packageName.contains('test'); + } + Widget _buildGenerosityHeader(String name) => Column( mainAxisSize: MainAxisSize.min, children: [