Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: 2 player improvements #1098

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/features/family/features/reflect/bloc/interview_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:givt_app/features/family/features/reflect/domain/models/game_profile.dart';
import 'package:givt_app/features/family/features/reflect/domain/models/record_answer_uimodel.dart';
import 'package:givt_app/features/family/features/reflect/domain/models/roles.dart';
import 'package:givt_app/features/family/features/reflect/domain/reflect_and_share_repository.dart';
import 'package:givt_app/features/family/features/reflect/presentation/models/interview_custom.dart';
import 'package:givt_app/shared/bloc/base_state.dart';
import 'package:givt_app/shared/bloc/common_cubit.dart';

class InterviewCubit extends CommonCubit<RecordAnswerUIModel, GameProfile> {
class InterviewCubit extends CommonCubit<RecordAnswerUIModel, InterviewCustom> {
InterviewCubit(this._reflectAndShareRepository)
: super(const BaseState.initial());

Expand Down Expand Up @@ -77,7 +77,16 @@ class InterviewCubit extends CommonCubit<RecordAnswerUIModel, GameProfile> {
}

void interviewFinished() {
emitCustom(getSidekick());
final sidekick = getSidekick();
if (sidekick.roles.length > 1) {
emitCustom(
const InterviewCustom.goToGratitudeSelection(),
);
} else {
emitCustom(
InterviewCustom.goToPassThePhoneToSidekick(profile: sidekick),
);
}
TammiLion marked this conversation as resolved.
Show resolved Hide resolved
}

void onCountdownStarted() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:givt_app/features/family/features/reflect/domain/models/game_profile.dart';

sealed class InterviewCustom {
const InterviewCustom();

const factory InterviewCustom.goToPassThePhoneToSidekick(
{required GameProfile profile}) = PassThePhoneToSidekick;

const factory InterviewCustom.goToGratitudeSelection() = GratitudeSelection;
}

class PassThePhoneToSidekick extends InterviewCustom {
const PassThePhoneToSidekick({
required this.profile,
});

final GameProfile profile;
}

class GratitudeSelection extends InterviewCustom {
const GratitudeSelection();
}
Original file line number Diff line number Diff line change
@@ -1,94 +1,41 @@
import 'package:flutter/material.dart';
import 'package:flutter_layout_grid/flutter_layout_grid.dart';
import 'package:givt_app/core/enums/enums.dart';
import 'package:givt_app/features/family/features/reflect/data/gratitude_category.dart';
import 'package:givt_app/features/family/features/reflect/presentation/models/gratitude_selection_uimodel.dart';
import 'package:givt_app/features/family/features/reflect/presentation/widgets/leave_game_button.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/features/family/utils/family_app_theme.dart';
import 'package:givt_app/shared/models/analytics_event.dart';
import 'package:givt_app/shared/widgets/fun_scaffold.dart';
import 'package:givt_app/features/family/app/injection.dart';
import 'package:givt_app/features/family/extensions/extensions.dart';
import 'package:givt_app/features/family/features/reflect/bloc/gratitude_selection_cubit.dart';
import 'package:givt_app/features/family/features/reflect/presentation/pages/guess_secret_word_screen.dart';
import 'package:givt_app/features/family/features/reflect/presentation/widgets/gratitude_selection_widget.dart';
import 'package:givt_app/shared/widgets/base/base_state_consumer.dart';

class GratitudeSelectionScreen extends StatefulWidget {
const GratitudeSelectionScreen({super.key});

@override
State<GratitudeSelectionScreen> createState() =>
_GratitudeSelectionScreenState();
}

class _GratitudeSelectionScreenState extends State<GratitudeSelectionScreen> {
final cubit = getIt<GratitudeSelectionCubit>();

@override
void didChangeDependencies() {
super.didChangeDependencies();
cubit.init();
}
TammiLion marked this conversation as resolved.
Show resolved Hide resolved

class GratitudeSelectionScreen extends StatelessWidget {
const GratitudeSelectionScreen({
required this.uimodel,
required this.onClickTile,
required this.onNext,
super.key,
});
final GratitudeSelectionUimodel uimodel;
final void Function(GratitudeCategory? gratitude) onClickTile;
final VoidCallback onNext;
@override
Widget build(BuildContext context) {
return FunScaffold(
appBar: FunTopAppBar.primary99(
title: 'Gratitude',
actions: const [
LeaveGameButton(),
],
),
body: Column(
children: [
const TitleMediumText(
'What was the superhero grateful for?',
color: FamilyAppTheme.primary30,
textAlign: TextAlign.center,
),
const SizedBox(height: 4),
const BodyMediumText('Choose one that fits the best'),
const SizedBox(height: 24),
LayoutGrid(
columnSizes: [1.fr, 1.fr],
rowSizes: const [
auto,
auto,
auto,
],
columnGap: 16,
rowGap: 16,
children: [
for (int i = 0; i < uimodel.gratitudeList.length; i++)
FunTile(
shrink: true,
titleBig: uimodel.gratitudeList[i].displayText,
assetSize: 27,
iconPath: '',
iconData: uimodel.gratitudeList[i].iconData,
iconColor: uimodel.gratitudeList[i].colorCombo.darkColor,
onTap: () {
onClickTile(uimodel.gratitudeList[i]);
},
isSelected:
uimodel.selectedGratitude == uimodel.gratitudeList[i],
borderColor: uimodel.gratitudeList[i].colorCombo.borderColor,
backgroundColor:
uimodel.gratitudeList[i].colorCombo.backgroundColor,
textColor: uimodel.gratitudeList[i].colorCombo.textColor,
analyticsEvent: AnalyticsEvent(
AmplitudeEvents.gratefulTileSelected,
parameters: {
'gratefulFor': uimodel.selectedGratitude?.displayText,
},
),
),
],
),
const Spacer(),
FunButton(
isDisabled: uimodel.selectedGratitude == null,
onTap: onNext,
text: 'Next',
analyticsEvent: AnalyticsEvent(
AmplitudeEvents.gratefulTileSubmitted,
parameters: {
'gratefulFor': uimodel.selectedGratitude?.displayText,
},
),
),
],
),
return BaseStateConsumer(
cubit: cubit,
onData: (context, uiModel) {
return GratitudeSelectionWidget(
uimodel: uiModel,
onClickTile: cubit.onClickTile,
onNext: () => Navigator.pushReplacement(
Comment on lines +31 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, thanks!

context,
const GuessSecretWordScreen().toRoute(context),
));
},
);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import 'package:flutter/material.dart';
import 'package:givt_app/app/injection/injection.dart';
import 'package:givt_app/core/enums/enums.dart';
import 'package:givt_app/features/family/extensions/extensions.dart';
import 'package:givt_app/features/family/features/reflect/bloc/gratitude_selection_cubit.dart';
import 'package:givt_app/features/family/features/reflect/domain/models/game_profile.dart';
import 'package:givt_app/features/family/features/reflect/presentation/pages/gratitude_selection_screen.dart';
import 'package:givt_app/features/family/features/reflect/presentation/pages/guess_secret_word_screen.dart';
import 'package:givt_app/features/family/features/reflect/presentation/pages/reveal_secret_word.dart';
import 'package:givt_app/features/family/features/reflect/presentation/widgets/game_profile_item.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/models/analytics_event.dart';
import 'package:givt_app/shared/widgets/base/base_state_consumer.dart';

class PassThePhone extends StatelessWidget {
const PassThePhone({
Expand All @@ -32,20 +28,10 @@ class PassThePhone extends StatelessWidget {
}

factory PassThePhone.toSidekick(GameProfile sidekick) {
final cubit = getIt<GratitudeSelectionCubit>()..init();
return PassThePhone(
user: sidekick,
onTap: (context) => Navigator.of(context).pushReplacement(
BaseStateConsumer(
cubit: cubit,
onData: (context, uiModel) => GratitudeSelectionScreen(
uimodel: uiModel,
onNext: () => Navigator.of(context).pushReplacement(
const GuessSecretWordScreen().toRoute(context),
),
onClickTile: cubit.onClickTile,
),
).toRoute(context),
const GratitudeSelectionScreen().toRoute(context),
),
buttonText: 'Continue',
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:givt_app/features/family/extensions/extensions.dart';
import 'package:givt_app/features/family/features/reflect/bloc/interview_cubit.dart';
import 'package:givt_app/features/family/features/reflect/domain/models/game_profile.dart';
import 'package:givt_app/features/family/features/reflect/domain/models/roles.dart';
import 'package:givt_app/features/family/features/reflect/presentation/models/interview_custom.dart';
import 'package:givt_app/features/family/features/reflect/presentation/pages/gratitude_selection_screen.dart';
import 'package:givt_app/features/family/features/reflect/presentation/pages/pass_the_phone_screen.dart';
import 'package:givt_app/features/family/features/reflect/presentation/pages/record_answer_screen.dart';
import 'package:givt_app/features/family/features/reflect/presentation/widgets/game_profile_item.dart';
Expand Down Expand Up @@ -67,11 +69,7 @@ class _StartInterviewScreenState extends State<StartInterviewScreen> {
BaseStateConsumer(
cubit: cubit,
onInitial: (context) => const SizedBox.shrink(),
onCustom: (context, sidekick) =>
Navigator.of(context).pushReplacement(
PassThePhone.toSidekick(sidekick)
.toRoute(context),
),
onCustom: _handleCustom,
onData: (context, uiModel) {
return RecordAnswerScreen(
uiModel: uiModel,
Expand Down Expand Up @@ -218,4 +216,18 @@ class _StartInterviewScreenState extends State<StartInterviewScreen> {
return FontAwesomeIcons.microphone;
}
}

void _handleCustom(BuildContext context, InterviewCustom custom) {
switch (custom) {
case final PassThePhoneToSidekick data:
Navigator.pushReplacement(
context,
PassThePhone.toSidekick(data.profile).toRoute(context),
);
case GratitudeSelection():
Navigator.of(context).pushReplacement(
const GratitudeSelectionScreen().toRoute(context),
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,21 @@ class GameProfileItem extends StatelessWidget {
),
Align(
alignment: Alignment.bottomCenter,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: List.generate(
profile.roles.length,
(i) => Container(
width: 36,
height: 36,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: profile.roles[i].color,
child: profile.roles.length == 2 ? SizedBox(
height: 36,width: (36*2)-4,
child: Stack(
children: [
Positioned(
right: 0,
child: _icon(profile.roles[1]),
),
child: Icon(
_getIconPerRole(profile.roles[i]),
color: FamilyAppTheme.primary20,
Positioned(
left: 0,
child: _icon(profile.roles[0]),
),
),
],
),
),
) : _iconRow(),
),
],
),
Expand All @@ -86,6 +82,32 @@ class GameProfileItem extends StatelessWidget {
);
}

Row _iconRow() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(
profile.roles.length,
(i) => _icon(profile.roles[i]),
),
);
}

Container _icon(Role role) {
return Container(
width: 36,
height: 36,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: role.color,
),
child: Icon(
_getIconPerRole(role),
size: 16,
color: FamilyAppTheme.primary20,
),
);
}

IconData _getIconPerRole(Role? role) {
switch (role.runtimeType) {
case SuperHero:
Expand Down
Loading