11import 'package:flutter/material.dart' ;
22import 'package:flutter_bloc/flutter_bloc.dart' ;
3+ import 'package:qack/constants/constants.dart' ;
34import 'package:qack/layout/layout_handler.dart' ;
45import 'package:qack/presentation/history/bloc/history_bloc.dart' ;
56import 'package:qack/presentation/history/repositories/history_repository.dart' ;
7+ import 'package:qack/presentation/settings/models/translator_details.dart' ;
68import 'package:qack/theme/theme.dart' ;
79import 'package:qack/utils/database/database.dart' ;
810import 'package:qack/widgets/input/input.dart' ;
@@ -17,15 +19,29 @@ class HistoryPage extends StatelessWidget {
1719 HistoryRepository (appDatabase: context.read <AppDatabase >()),
1820 ),
1921 child: const LayoutHandler (
20- mobile: HistoryView (),
21- tablet: HistoryView (),
22+ mobile: HistoryView (
23+ searchBarPadding: EdgeInsets .only (
24+ top: 16 ,
25+ left: PaddingConstants .mobileHorizontalMarginValue,
26+ right: PaddingConstants .mobileHorizontalMarginValue,
27+ ),
28+ ),
29+ tablet: HistoryView (
30+ searchBarPadding: EdgeInsets .only (
31+ top: 24 ,
32+ left: PaddingConstants .tabletHorizontalMarginValue,
33+ right: PaddingConstants .tabletHorizontalMarginValue,
34+ ),
35+ ),
2236 ),
2337 );
2438 }
2539}
2640
2741class HistoryView extends StatefulWidget {
28- const HistoryView ({super .key});
42+ const HistoryView ({required this .searchBarPadding, super .key});
43+
44+ final EdgeInsets searchBarPadding;
2945
3046 @override
3147 State <HistoryView > createState () => _HistoryViewState ();
@@ -45,10 +61,15 @@ class _HistoryViewState extends State<HistoryView> {
4561 body: SafeArea (
4662 child: CustomScrollView (
4763 slivers: [
48- const SliverPadding (
49- padding: EdgeInsets . only (top : 16 ) ,
64+ SliverPadding (
65+ padding: widget.searchBarPadding ,
5066 sliver: SliverToBoxAdapter (
51- child: AppSearchBar (),
67+ child: AppSearchBar (
68+ onChanged: (query) {
69+ context.read <HistoryBloc >().add (HistoryFiltered (query));
70+ },
71+ hintText: 'Search' ,
72+ ),
5273 ),
5374 ),
5475 SliverPadding (
@@ -70,7 +91,7 @@ class _HistoryViewState extends State<HistoryView> {
7091 ),
7192 ),
7293 );
73- } else if (state.history .isEmpty) {
94+ } else if (state.filteredHistory .isEmpty) {
7495 // TODO: only show this text if history and filter
7596 // are empty
7697 return const Center (
@@ -79,18 +100,22 @@ class _HistoryViewState extends State<HistoryView> {
79100 }
80101
81102 // Temporary history
82- final translationHistory = state.history [index];
103+ final translationHistory = state.filteredHistory [index];
83104 return ListTile (
84105 title: Text (translationHistory.input),
85106 subtitle: Text (
86107 translationHistory.items
87- ? .map ((item) => item.output)
88- .join ('\n ' ) ??
108+ ? .map (
109+ (item) =>
110+ '${item .translator .toTranslator ()}: '
111+ '${item .output }' ,
112+ )
113+ .join ('\n\n ' ) ??
89114 '' ,
90115 ),
91116 );
92117 },
93- childCount: state.history .length,
118+ childCount: state.filteredHistory .length,
94119 ),
95120 );
96121 },
0 commit comments