Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
feat: add thinking animation to Dash when ask again (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiMiguel authored Dec 13, 2023
1 parent b96d1d3 commit 7692037
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
5 changes: 4 additions & 1 deletion lib/home/bloc/home_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,17 @@ extension StatusX on Status {
this == Status.seeSourceAnswers ||
this == Status.sourceAnswersBackToResults;
bool get isSeeSourceAnswersVisible => this == Status.seeSourceAnswers;
bool get isThinking =>
this == Status.askQuestionToThinking || this == Status.resultsToThinking;
bool get isDashOnLeft =>
this == Status.welcome ||
this == Status.welcomeToAskQuestion ||
this == Status.askQuestion ||
this == Status.askQuestionToThinking ||
this == Status.thinking ||
this == Status.thinkingToResults ||
this == Status.results;
this == Status.results ||
this == Status.resultsToThinking;
bool get isDashOnRight =>
this == Status.resultsToSourceAnswers ||
this == Status.seeSourceAnswers ||
Expand Down
19 changes: 4 additions & 15 deletions lib/home/widgets/dash_animation_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class _DashAnimationContainerState extends State<DashAnimationContainer> {
} else {
if (state.status == Status.resultsToSourceAnswers) {
_state.value = DashAnimationPhase.dashOut;
} else if (state.status == Status.thinkingToResults ||
state.status == Status.sourceAnswersBackToResults) {
} else if (state.status == Status.sourceAnswersBackToResults) {
_state.value = DashAnimationPhase.dashIn;
}
}
Expand Down Expand Up @@ -173,21 +172,11 @@ class DashSpriteAnimationState extends State<DashSpriteAnimation> {
BlocListener<HomeBloc, HomeState>(
listenWhen: (previous, current) =>
previous.status != current.status &&
current.status == Status.askQuestionToThinking,
(current.status.isThinking),
listener: (context, state) {
thinkingTicker = animations.thinkingAnimation.createTicker();
},
),
BlocListener<HomeBloc, HomeState>(
listenWhen: (previous, current) =>
previous.status != current.status &&
current.status == Status.thinkingToResults,
listener: (context, state) {
setState(() {
_reaction = animations.thinkingAnimation.reversed();
});
},
),
],
child: BlocBuilder<HomeBloc, HomeState>(
builder: (context, state) {
Expand Down Expand Up @@ -217,11 +206,11 @@ class DashSpriteAnimationState extends State<DashSpriteAnimation> {
);
}

final idleAnimation = state.status == Status.askQuestionToThinking
final idleAnimation = state.status.isThinking
? animations.thinkingAnimation
: animations.idleAnimation;

final idleTicker = state.status == Status.askQuestionToThinking
final idleTicker = state.status.isThinking
? thinkingTicker
: idleAnimation.createTicker();

Expand Down

0 comments on commit 7692037

Please sign in to comment.