LCOV - code coverage report
Current view: top level - lib/pages/bill - bill_search_page.dart Coverage Total Hit
Test: lcov.info Lines: 0.0 % 116 0
Test Date: 2026-12-05 10:50:38 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            0 :   const BillSearchPage({super.key});
      29              : 
      30            0 :   @override
      31            0 :   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              :   late List<ListAccountSelectorItem> accountList =
      47              :       state.getList(AppDataType.accounts).map((item) => ListAccountSelectorItem(item: item)).toList();
      48              :   late List<ListAccountSelectorItem> budgetList =
      49              :       state.getList(AppDataType.budgets).map((item) => ListAccountSelectorItem(item: item)).toList();
      50              : 
      51            0 :   @override
      52              :   void initState() {
      53            0 :     description = TextEditingController();
      54            0 :     amountFrom = TextEditingController();
      55            0 :     amountTo = TextEditingController();
      56            0 :     tags = ValueNotifier([]);
      57            0 :     tags.addListener(() => setState(clearState));
      58            0 :     focus = FocusController();
      59            0 :     super.initState();
      60              :   }
      61              : 
      62            0 :   @override
      63              :   dispose() {
      64            0 :     description.dispose();
      65            0 :     amountFrom.dispose();
      66            0 :     amountTo.dispose();
      67            0 :     tags.dispose();
      68            0 :     focus.dispose();
      69            0 :     super.dispose();
      70              :   }
      71              : 
      72            0 :   @override
      73            0 :   String getTitle() => AppLocale.labels.searchTooltip;
      74              : 
      75            0 :   @override
      76            0 :   String getButtonName() => AppLocale.labels.searchTooltip;
      77              : 
      78            0 :   @override
      79              :   Widget buildButton(BuildContext context, BoxConstraints constraints) {
      80            0 :     return FloatingActionButton(
      81              :       heroTag: 'bill_search_page',
      82            0 :       onPressed: () => setState(clearState),
      83            0 :       tooltip: getButtonName(),
      84              :       child: const Icon(Icons.search),
      85              :     );
      86              :   }
      87              : 
      88            0 :   bool getContentFilter(BillAppData item) {
      89            0 :     final descriptionMatch = item.title.toLowerCase().contains(description.text.toLowerCase());
      90            0 :     final tagsMatch = item.tags.hasTags(tags.value);
      91            0 :     final accountMatch = account == null || item.account == account;
      92            0 :     final budgetMatch = budget == null || item.category == budget;
      93            0 :     final typeMatch = type == null || state.getByUuid(item.account)?.type == type;
      94            0 :     final currencyMatch = currency == null || item.currency == currency;
      95            0 :     final startDateMatch = startDate == null || item.createdAt.isAfter(startDate!);
      96            0 :     final endDateMatch = endDate == null || item.createdAt.isBefore(endDate!);
      97            0 :     final amountFromMatch = amountFrom.text.isEmpty || item.details >= double.tryParse(amountFrom.text)!;
      98            0 :     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            0 :   @override
     112            0 :   InterfaceIterator getContentStream() => state.getStream<BillAppData>(AppDataType.bills, filter: getContentFilter);
     113              : 
     114            0 :   @override
     115              :   Widget addHeaderWidget() {
     116            0 :     final width = ScreenHelper.state().width - ThemeHelper.getIndent(4);
     117            0 :     final indent = ThemeHelper.getIndent(2);
     118            0 :     return SliverToBoxAdapter(
     119            0 :       child: SingleScrollWrapper(
     120            0 :         controller: focus,
     121            0 :         child: Column(
     122            0 :           crossAxisAlignment: AppDesign.getAlignment(),
     123            0 :           children: [
     124            0 :             InputWrapper.text(
     125            0 :               title: AppLocale.labels.description,
     126            0 :               controller: description,
     127            0 :               tooltip: AppLocale.labels.descriptionTooltip,
     128              :             ),
     129            0 :             TagsInput(
     130            0 :               title: AppLocale.labels.tags,
     131            0 :               tooltip: AppLocale.labels.tagsTooltip,
     132            0 :               controller: tags,
     133              :             ),
     134            0 :             RowWidget(
     135              :               indent: indent,
     136            0 :               maxWidth: width + indent,
     137              :               chunk: const [0.5, 0.5],
     138            0 :               children: [
     139            0 :                 [
     140            0 :                   InputWrapper.text(
     141            0 :                     title: AppLocale.labels.amountFrom,
     142            0 :                     tooltip: AppLocale.labels.billSetTooltip,
     143            0 :                     controller: amountFrom,
     144              :                     inputType: const TextInputType.numberWithOptions(decimal: true),
     145            0 :                     formatter: [
     146            0 :                       SimpleInputFormatter.filterDouble,
     147              :                     ],
     148              :                   ),
     149              :                 ],
     150            0 :                 [
     151            0 :                   InputWrapper.text(
     152            0 :                     title: AppLocale.labels.amountTo,
     153            0 :                     tooltip: AppLocale.labels.billSetTooltip,
     154            0 :                     controller: amountTo,
     155              :                     inputType: const TextInputType.numberWithOptions(decimal: true),
     156            0 :                     formatter: [
     157            0 :                       SimpleInputFormatter.filterDouble,
     158              :                     ],
     159              :                   ),
     160              :                 ],
     161              :               ],
     162              :             ),
     163            0 :             InputWrapper.select(
     164            0 :               value: type,
     165            0 :               title: AppLocale.labels.accountType,
     166            0 :               tooltip: AppLocale.labels.accountTypeTooltip,
     167            0 :               options: AccountType.getList(),
     168            0 :               onChange: (value) => setState(() {
     169            0 :                 if (value != type) clearState();
     170            0 :                 type = value;
     171              :               }),
     172              :             ),
     173            0 :             InputWrapper(
     174              :               type: NamedInputType.accountSelector,
     175            0 :               value: account != null ? state.getByUuid(account!) : null,
     176            0 :               title: AppLocale.labels.account,
     177            0 :               tooltip: AppLocale.labels.titleAccountTooltip,
     178            0 :               state: state,
     179            0 :               options: accountList,
     180            0 :               onChange: (value) => setState(() {
     181            0 :                 if (value?.uuid != account) clearState();
     182            0 :                 account = value?.uuid;
     183              :               }),
     184              :               width: width,
     185              :             ),
     186            0 :             InputWrapper(
     187              :               type: NamedInputType.budgetSelector,
     188            0 :               value: budget != null ? state.getByUuid(budget!) : null,
     189            0 :               title: AppLocale.labels.budget,
     190            0 :               tooltip: AppLocale.labels.titleBudgetTooltip,
     191            0 :               state: state,
     192            0 :               options: budgetList,
     193            0 :               onChange: (value) => setState(() {
     194            0 :                 if (value?.uuid != budget) clearState();
     195            0 :                 budget = value?.uuid;
     196              :               }),
     197              :               width: width,
     198              :             ),
     199            0 :             InputWrapper.currency(
     200            0 :               value: currency,
     201            0 :               title: AppLocale.labels.currency,
     202            0 :               tooltip: AppLocale.labels.currencyTooltip,
     203            0 :               onChange: (value) => setState(() {
     204            0 :                 if (value != currency) clearState();
     205            0 :                 currency = value;
     206              :               }),
     207              :             ),
     208            0 :             TextWrapper(
     209            0 :               AppLocale.labels.dateRange,
     210            0 :               style: context.textTheme.bodyLarge,
     211              :             ),
     212            0 :             DateRangeInput(
     213            0 :               valueFrom: startDate,
     214            0 :               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