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

feat: card transition back summary #65

Merged
merged 4 commits into from
Dec 5, 2023
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
27 changes: 14 additions & 13 deletions lib/home/bloc/home_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,21 @@ class HomeState extends Equatable {
status == Status.sourceAnswersBackToResults;
bool get isMovingToSeeSourceAnswers =>
status == Status.resultsToSourceAnswers ||
status == Status.seeSourceAnswers;
status == Status.seeSourceAnswers ||
status == Status.sourceAnswersBackToResults;
bool get isSeeSourceAnswersVisible => status == Status.seeSourceAnswers;
bool get isDashVisible => [
Status.welcome,
Status.welcomeToAskQuestion,
Status.askQuestion,
Status.askQuestionToThinking,
Status.thinking,
Status.thinkingToResults,
Status.results,
Status.resultsToSourceAnswers,
Status.seeSourceAnswers,
Status.sourceAnswersBackToResults,
].contains(status);
bool get isDashOnLeft =>
status == Status.welcome ||
status == Status.welcomeToAskQuestion ||
status == Status.askQuestion ||
status == Status.askQuestionToThinking ||
status == Status.thinking ||
status == Status.thinkingToResults ||
status == Status.results;
bool get isDashOnRight =>
status == Status.resultsToSourceAnswers ||
status == Status.seeSourceAnswers ||
status == Status.sourceAnswersBackToResults;

HomeState copyWith({
Status? status,
Expand Down
12 changes: 3 additions & 9 deletions lib/home/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,15 @@ class HomePage extends StatelessWidget {

class HomeView extends StatelessWidget {
@visibleForTesting
const HomeView({
super.key,
@visibleForTesting this.dashOnRightStatus = Status.seeSourceAnswers,
});
const HomeView({super.key});

static const _dashRightKey = Key('dashAnimationContainer_right');
static const _dashLeftKey = Key('dashAnimationContainer_left');

final Status dashOnRightStatus;

@override
Widget build(BuildContext context) {
final state = context.watch<HomeBloc>().state;

final isDashOnRight = state.status == dashOnRightStatus;
return Scaffold(
backgroundColor: VertexColors.arctic,
body: Stack(
Expand All @@ -54,7 +48,7 @@ class HomeView extends StatelessWidget {
left: 48,
child: Logo(hasDarkBackground: state.isSeeSourceAnswersVisible),
),
if (state.isDashVisible && isDashOnRight)
if (state.isDashOnRight)
const Positioned(
bottom: 50,
right: 50,
Expand All @@ -63,7 +57,7 @@ class HomeView extends StatelessWidget {
key: _dashRightKey,
),
),
if (state.isDashVisible && !isDashOnRight)
if (state.isDashOnLeft)
const Positioned(
bottom: 50,
left: 50,
Expand Down
18 changes: 13 additions & 5 deletions lib/home/widgets/dash_animation_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ class _DashAnimationContainerState extends State<DashAnimationContainer> {
Widget build(BuildContext context) {
return BlocListener<HomeBloc, HomeState>(
listener: (context, state) {
if (state.status == Status.resultsToSourceAnswers) {
_state.value = DashAnimationPhase.dashOut;
} else if (state.status == Status.thinkingToResults ||
state.status == Status.seeSourceAnswers) {
_state.value = DashAnimationPhase.dashIn;
if (widget.right) {
if (state.status == Status.sourceAnswersBackToResults) {
_state.value = DashAnimationPhase.dashOut;
} else if (state.status == Status.resultsToSourceAnswers) {
_state.value = DashAnimationPhase.dashIn;
}
} else {
if (state.status == Status.resultsToSourceAnswers) {
_state.value = DashAnimationPhase.dashOut;
} else if (state.status == Status.thinkingToResults ||
state.status == Status.sourceAnswersBackToResults) {
_state.value = DashAnimationPhase.dashIn;
}
}
},
child: DashAnimation(
Expand Down
19 changes: 14 additions & 5 deletions lib/home/widgets/results_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ enum ResultsAnimationPhase {
const _searchBarTopPadding = 90.0;
const _questionBoxHeight = 84.0;
const _cardEnterDuration = Duration(seconds: 2);
const _cardExpandDuration = Duration(milliseconds: 800);
const _cardExpandDuration = Duration(seconds: 1);
const _carouselEnterDuration = Duration(seconds: 1);

class ResultsView extends StatefulWidget {
const ResultsView({super.key});
Expand Down Expand Up @@ -216,6 +217,11 @@ class BlueContainerState extends State<BlueContainer>
state.status == Status.resultsToSourceAnswers) {
context.read<HomeBloc>().add(const SeeResultsSourceAnswers());
}

if (status == AnimationStatus.dismissed &&
state.status == Status.sourceAnswersBackToResults) {
context.read<HomeBloc>().add(const Results());
}
});
}

Expand Down Expand Up @@ -580,18 +586,21 @@ class CarouselViewState extends State<CarouselView>
@override
List<Status> get forwardEnterStatuses => [Status.resultsToSourceAnswers];

@override
List<Status> get backExitStatuses => [Status.sourceAnswersBackToResults];

@override
void initializeTransitionController() {
super.initializeTransitionController();

enterTransitionController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
duration: _carouselEnterDuration,
);

exitTransitionController = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
duration: const Duration(seconds: 1),
);
}

Expand All @@ -600,14 +609,14 @@ class CarouselViewState extends State<CarouselView>
super.initState();

_offsetEnterIn =
Tween<Offset>(begin: const Offset(1, 0), end: Offset.zero).animate(
Tween<Offset>(begin: const Offset(1.5, 0), end: Offset.zero).animate(
CurvedAnimation(
parent: enterTransitionController,
curve: Curves.decelerate,
),
);

_rotationEnterIn = Tween<double>(begin: 0.2, end: 0).animate(
_rotationEnterIn = Tween<double>(begin: 0.1, end: 0).animate(
CurvedAnimation(
parent: enterTransitionController,
curve: Curves.decelerate,
Expand Down
55 changes: 49 additions & 6 deletions test/home/view/home_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:api_client/api_client.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:dash_ai_search/animations.dart';
import 'package:dash_ai_search/home/home.dart';
Expand Down Expand Up @@ -44,6 +45,49 @@ void main() {
});

group('HomeView', () {
const response = VertexResponse(
summary: 'Flutter is a free and open source software development '
"kit (SDK) from Google [1]. It's used to create beautiful, "
'fast user experiences, ,,,for mobile, web, and desktop '
'applications [1]. Flutter works with existing code and is used '
'by developers and organizations around the world [1]. [3]. '
'Flutter is a fully open source project [3].',
documents: [
VertexDocument(
id: '1',
metadata: VertexMetadata(
url: 'url',
title: 'title',
description: 'description',
),
),
VertexDocument(
id: '2',
metadata: VertexMetadata(
url: 'url',
title: 'title',
description: 'description',
),
),
VertexDocument(
id: '3',
metadata: VertexMetadata(
url: 'url',
title: 'title',
description: 'description',
),
),
VertexDocument(
id: '4',
metadata: VertexMetadata(
url: 'url',
title: 'title',
description: 'description',
),
),
],
);

late HomeBloc homeBloc;
late DashAnimations dashAnimations;

Expand Down Expand Up @@ -106,8 +150,7 @@ void main() {
});

testWidgets(
'renders DashAnimationContainer on the left if dash is '
'visible and is not sources',
'renders DashAnimationContainer on the left if dash is visible',
(tester) async {
when(() => homeBloc.state).thenReturn(
HomeState(
Expand All @@ -125,20 +168,20 @@ void main() {
);

testWidgets(
'renders DashAnimationContainer on the left if dash is '
'visible and is not sources',
'renders DashAnimationContainer on the right if dash is visible',
(tester) async {
when(() => homeBloc.state).thenReturn(
HomeState(
status: Status.results,
status: Status.seeSourceAnswers,
vertexResponse: response,
),
);
await tester.pumpApp(
RepositoryProvider.value(
value: dashAnimations,
child: BlocProvider.value(
value: homeBloc,
child: HomeView(dashOnRightStatus: Status.results),
child: HomeView(),
),
),
);
Expand Down
Loading