LCOV - code coverage report
Current view: top level - lib/pages/bill - bill_search_page.dart Coverage Total Hit
Test: lcov.info Lines: 91.7 % 120 110
Test Date: 2026-12-05 10:54:13 Functions: - 0 0

            Line data    Source code
       1              : // Copyright 2025 The terCAD team. All rights reserved.
       2              : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
       3              : 
       4              : import 'package:app_finance/_classes/controller/iterator_controller.dart';
       5              : import 'package:app_finance/_classes/controller/focus_controller.dart';
       6              : import 'package:app_finance/_classes/herald/app_design.dart';
       7              : import 'package:app_finance/_classes/herald/app_locale.dart';
       8              : import 'package:app_finance/_classes/storage/app_data.dart';
       9              : import 'package:app_finance/_classes/structure/bill_app_data.dart';
      10              : import 'package:app_finance/_configs/account_type.dart';
      11              : import 'package:app_finance/_configs/screen_helper.dart';
      12              : import 'package:app_finance/_configs/theme_helper.dart';
      13              : import 'package:app_finance/_ext/build_context_ext.dart';
      14              : import 'package:app_finance/_ext/tags_ext.dart';
      15              : import 'package:app_finance/design/form/date_range_input.dart';
      16              : import 'package:app_finance/design/form/list_account_selector.dart';
      17              : import 'package:app_finance/design/form/simple_input.dart';
      18              : import 'package:app_finance/design/form/tags_input.dart';
      19              : import 'package:app_finance/design/wrapper/input_wrapper.dart';
      20              : import 'package:app_finance/design/wrapper/row_widget.dart';
      21              : import 'package:app_finance/design/wrapper/single_scroll_wrapper.dart';
      22              : import 'package:app_finance/design/wrapper/text_wrapper.dart';
      23              : import 'package:app_finance/pages/bill/bill_page.dart';
      24              : import 'package:material_ui/material_ui.dart';
      25              : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
      26              : 
      27              : class BillSearchPage extends StatefulWidget {
      28            1 :   const BillSearchPage({super.key});
      29              : 
      30            1 :   @override
      31            1 :   BillViewPageState createState() => BillViewPageState();
      32              : }
      33              : 
      34              : class BillViewPageState extends BillPageState<BillSearchPage> {
      35              :   String? account;
      36              :   String? budget;
      37              :   String? type;
      38              :   Currency? currency;
      39              :   DateTime? startDate;
      40              :   DateTime? endDate;
      41              :   late TextEditingController description;
      42              :   late TextEditingController amountFrom;
      43              :   late TextEditingController amountTo;
      44              :   late ValueNotifier<List<String>> tags;
      45              :   late FocusController focus;
      46            1 :   late List<ListAccountSelectorItem> accountList =
      47            6 :       state.getList(AppDataType.accounts).map((item) => ListAccountSelectorItem(item: item)).toList();
      48            1 :   late List<ListAccountSelectorItem> budgetList =
      49            6 :       state.getList(AppDataType.budgets).map((item) => ListAccountSelectorItem(item: item)).toList();
      50              : 
      51            1 :   @override
      52              :   void initState() {
      53            2 :     description = TextEditingController();
      54            2 :     amountFrom = TextEditingController();
      55            2 :     amountTo = TextEditingController();
      56            3 :     tags = ValueNotifier([]);
      57            2 :     tags.addListener(() => setState(clearState));
      58            2 :     focus = FocusController();
      59            1 :     super.initState();
      60              :   }
      61              : 
      62            1 :   @override
      63              :   dispose() {
      64            2 :     description.dispose();
      65            2 :     amountFrom.dispose();
      66            2 :     amountTo.dispose();
      67            2 :     tags.dispose();
      68            2 :     focus.dispose();
      69            1 :     super.dispose();
      70              :   }
      71              : 
      72            1 :   @override
      73            2 :   String getTitle() => AppLocale.labels.searchTooltip;
      74              : 
      75            1 :   @override
      76            2 :   String getButtonName() => AppLocale.labels.searchTooltip;
      77              : 
      78            1 :   @override
      79              :   Widget buildButton(BuildContext context, BoxConstraints constraints) {
      80            1 :     return FloatingActionButton(
      81              :       heroTag: 'bill_search_page',
      82            3 :       onPressed: () => setState(clearState),
      83            1 :       tooltip: getButtonName(),
      84              :       child: const Icon(Icons.search),
      85              :     );
      86              :   }
      87              : 
      88            1 :   bool getContentFilter(BillAppData item) {
      89            6 :     final descriptionMatch = item.title.toLowerCase().contains(description.text.toLowerCase());
      90            4 :     final tagsMatch = item.tags.hasTags(tags.value);
      91            4 :     final accountMatch = account == null || item.account == account;
      92            4 :     final budgetMatch = budget == null || item.category == budget;
      93            1 :     final typeMatch = type == null || state.getByUuid(item.account)?.type == type;
      94            1 :     final currencyMatch = currency == null || item.currency == currency;
      95            1 :     final startDateMatch = startDate == null || item.createdAt.isAfter(startDate!);
      96            1 :     final endDateMatch = endDate == null || item.createdAt.isBefore(endDate!);
      97            3 :     final amountFromMatch = amountFrom.text.isEmpty || item.details >= double.tryParse(amountFrom.text)!;
      98            3 :     final amountToMatch = amountTo.text.isEmpty || item.details <= double.tryParse(amountTo.text)!;
      99              :     return !(descriptionMatch &&
     100              :         tagsMatch &&
     101              :         accountMatch &&
     102              :         budgetMatch &&
     103              :         typeMatch &&
     104              :         currencyMatch &&
     105              :         startDateMatch &&
     106              :         endDateMatch &&
     107              :         amountFromMatch &&
     108              :         amountToMatch);
     109              :   }
     110              : 
     111            1 :   @override
     112            3 :   InterfaceIterator getContentStream() => state.getStream<BillAppData>(AppDataType.bills, filter: getContentFilter);
     113              : 
     114            1 :   @override
     115              :   Widget addHeaderWidget() {
     116            3 :     final width = ScreenHelper.state().width - ThemeHelper.getIndent(4);
     117            1 :     final indent = ThemeHelper.getIndent(2);
     118            1 :     return SliverToBoxAdapter(
     119            1 :       child: SingleScrollWrapper(
     120            1 :         controller: focus,
     121            1 :         child: Column(
     122            1 :           crossAxisAlignment: AppDesign.getAlignment(),
     123            1 :           children: [
     124            1 :             InputWrapper.text(
     125            2 :               title: AppLocale.labels.description,
     126            1 :               controller: description,
     127            2 :               tooltip: AppLocale.labels.descriptionTooltip,
     128              :             ),
     129            1 :             TagsInput(
     130            2 :               title: AppLocale.labels.tags,
     131            2 :               tooltip: AppLocale.labels.tagsTooltip,
     132            1 :               controller: tags,
     133              :             ),
     134            1 :             RowWidget(
     135              :               indent: indent,
     136            1 :               maxWidth: width + indent,
     137              :               chunk: const [0.5, 0.5],
     138            1 :               children: [
     139            1 :                 [
     140            1 :                   InputWrapper.text(
     141            2 :                     title: AppLocale.labels.amountFrom,
     142            2 :                     tooltip: AppLocale.labels.billSetTooltip,
     143            1 :                     controller: amountFrom,
     144              :                     inputType: const TextInputType.numberWithOptions(decimal: true),
     145            1 :                     formatter: [
     146            1 :                       SimpleInputFormatter.filterDouble,
     147              :                     ],
     148              :                   ),
     149              :                 ],
     150            1 :                 [
     151            1 :                   InputWrapper.text(
     152            2 :                     title: AppLocale.labels.amountTo,
     153            2 :                     tooltip: AppLocale.labels.billSetTooltip,
     154            1 :                     controller: amountTo,
     155              :                     inputType: const TextInputType.numberWithOptions(decimal: true),
     156            1 :                     formatter: [
     157            1 :                       SimpleInputFormatter.filterDouble,
     158              :                     ],
     159              :                   ),
     160              :                 ],
     161              :               ],
     162              :             ),
     163            1 :             InputWrapper.select(
     164            1 :               value: type,
     165            2 :               title: AppLocale.labels.accountType,
     166            2 :               tooltip: AppLocale.labels.accountTypeTooltip,
     167            1 :               options: AccountType.getList(),
     168            0 :               onChange: (value) => setState(() {
     169            0 :                 if (value != type) clearState();
     170            0 :                 type = value;
     171              :               }),
     172              :             ),
     173            1 :             InputWrapper(
     174              :               type: NamedInputType.accountSelector,
     175            4 :               value: account != null ? state.getByUuid(account!) : null,
     176            2 :               title: AppLocale.labels.account,
     177            2 :               tooltip: AppLocale.labels.titleAccountTooltip,
     178            1 :               state: state,
     179            1 :               options: accountList,
     180            3 :               onChange: (value) => setState(() {
     181            4 :                 if (value?.uuid != account) clearState();
     182            2 :                 account = value?.uuid;
     183              :               }),
     184              :               width: width,
     185              :             ),
     186            1 :             InputWrapper(
     187              :               type: NamedInputType.budgetSelector,
     188            4 :               value: budget != null ? state.getByUuid(budget!) : null,
     189            2 :               title: AppLocale.labels.budget,
     190            2 :               tooltip: AppLocale.labels.titleBudgetTooltip,
     191            1 :               state: state,
     192            1 :               options: budgetList,
     193            3 :               onChange: (value) => setState(() {
     194            4 :                 if (value?.uuid != budget) clearState();
     195            2 :                 budget = value?.uuid;
     196              :               }),
     197              :               width: width,
     198              :             ),
     199            1 :             InputWrapper.currency(
     200            1 :               value: currency,
     201            2 :               title: AppLocale.labels.currency,
     202            2 :               tooltip: AppLocale.labels.currencyTooltip,
     203            0 :               onChange: (value) => setState(() {
     204            0 :                 if (value != currency) clearState();
     205            0 :                 currency = value;
     206              :               }),
     207              :             ),
     208            1 :             TextWrapper(
     209            2 :               AppLocale.labels.dateRange,
     210            3 :               style: context.textTheme.bodyLarge,
     211              :             ),
     212            1 :             DateRangeInput(
     213            1 :               valueFrom: startDate,
     214            1 :               value: endDate,
     215            0 :               setState: (start, end) => setState(() {
     216            0 :                 startDate = start;
     217            0 :                 endDate = end;
     218            0 :                 clearState();
     219              :               }),
     220              :             ),
     221              :           ],
     222              :         ),
     223              :       ),
     224              :     );
     225              :   }
     226              : }
        

Generated by: LCOV version 2.0-1