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

Commit

Permalink
feat: add search box to results and source answers views (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecoca authored Nov 28, 2023
1 parent 57d02af commit 3e96e3a
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 17 deletions.
10 changes: 1 addition & 9 deletions lib/home/widgets/question_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,7 @@ class _QuestionView extends StatelessWidget {
?.copyWith(color: VertexColors.flutterNavy),
),
const SizedBox(height: 40),
QuestionInputTextField(
icon: vertexIcons.stars.image(),
hint: l10n.questionHint,
actionText: l10n.ask,
onTextUpdated: (String query) =>
context.read<HomeBloc>().add(QueryUpdated(query: query)),
onActionPressed: () =>
context.read<HomeBloc>().add(const QuestionAsked()),
),
const SearchBox(),
],
),
),
Expand Down
18 changes: 14 additions & 4 deletions lib/home/widgets/results_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ class ResultsView extends StatelessWidget {
Widget build(BuildContext context) {
final response =
context.select((HomeBloc bloc) => bloc.state.vertexResponse);
return Stack(
children: [
Align(child: BlueContainer(summary: response.summary)),
],
return SingleChildScrollView(
child: Column(
children: [
const SizedBox(height: 64),
const SearchBox(),
const SizedBox(height: 32),
Stack(
children: [
Align(child: BlueContainer(summary: response.summary)),
],
),
const SizedBox(height: 32),
],
),
);
}
}
Expand Down
25 changes: 25 additions & 0 deletions lib/home/widgets/search_box.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:app_ui/app_ui.dart';
import 'package:dash_ai_search/home/home.dart';
import 'package:dash_ai_search/l10n/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class SearchBox extends StatelessWidget {
const SearchBox({super.key});

@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final searchQuery = context.select((HomeBloc bloc) => bloc.state.query);
return QuestionInputTextField(
icon: vertexIcons.stars.image(),
hint: l10n.questionHint,
actionText: l10n.ask,
onTextUpdated: (String query) =>
context.read<HomeBloc>().add(QueryUpdated(query: query)),
onActionPressed: () =>
context.read<HomeBloc>().add(const QuestionAsked()),
text: searchQuery.isEmpty ? null : searchQuery,
);
}
}
4 changes: 3 additions & 1 deletion lib/home/widgets/see_source_answers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class SeeSourceAnswers extends StatelessWidget {
color: VertexColors.googleBlue,
child: Column(
children: [
const SizedBox(height: 100),
const SizedBox(height: 64),
const SearchBox(),
const SizedBox(height: 32),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 50),
child: Row(
Expand Down
1 change: 1 addition & 0 deletions lib/home/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export 'circle.dart';
export 'logo.dart';
export 'question_view.dart';
export 'results_view.dart';
export 'search_box.dart';
export 'thinking_view.dart';
export 'welcome_view.dart';
10 changes: 8 additions & 2 deletions packages/app_ui/lib/src/widgets/question_input_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class QuestionInputTextField extends StatefulWidget {
required this.actionText,
required this.onTextUpdated,
required this.onActionPressed,
this.text,
super.key,
});

Expand All @@ -31,6 +32,9 @@ class QuestionInputTextField extends StatefulWidget {
///
final VoidCallback onActionPressed;

/// Initial text displayed in the text field
final String? text;

@override
State<QuestionInputTextField> createState() => _QuestionTextFieldState();
}
Expand All @@ -41,7 +45,7 @@ class _QuestionTextFieldState extends State<QuestionInputTextField> {
@override
void initState() {
super.initState();
_controller = TextEditingController();
_controller = TextEditingController(text: widget.text);
_controller.addListener(() {
widget.onTextUpdated(_controller.text);
});
Expand All @@ -57,13 +61,15 @@ class _QuestionTextFieldState extends State<QuestionInputTextField> {
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;
return Container(
constraints: const BoxConstraints(maxWidth: 659),
constraints: const BoxConstraints(maxWidth: 600),
child: TextField(
controller: _controller,
style: textTheme.bodyMedium?.copyWith(
color: VertexColors.flutterNavy,
),
decoration: InputDecoration(
filled: true,
fillColor: VertexColors.arctic,
prefixIcon: Padding(
padding: const EdgeInsets.only(left: 12),
child: widget.icon,
Expand Down
8 changes: 7 additions & 1 deletion test/home/view/home_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:dash_ai_search/home/home.dart';
import 'package:dash_ai_search/home/widgets/see_source_answers.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
Expand Down Expand Up @@ -112,7 +113,12 @@ void main() {
child: HomeView(),
),
);
expect(find.byType(SeeSourceAnswersButton), findsOneWidget);
final answersFinder = find.byType(SeeSourceAnswersButton);
await tester.dragUntilVisible(
answersFinder,
find.byType(SingleChildScrollView),
const Offset(0, 10),
);
await tester.tap(find.byType(SeeSourceAnswersButton));
verify(() => homeBloc.add(const SeeSourceAnswersRequested())).called(1);
});
Expand Down
1 change: 1 addition & 0 deletions test/home/widgets/see_source_answers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void main() {
child: Material(child: SeeSourceAnswers()),
),
);
expect(find.byType(SearchBox), findsOneWidget);
expect(find.text(response.summary), findsOneWidget);
expect(find.text(response.documents.length.toString()), findsOneWidget);
expect(find.byType(Placeholder), findsOneWidget);
Expand Down

0 comments on commit 3e96e3a

Please sign in to comment.