LCOV - code coverage report
Current view: top level - lib/pages/account - account_page.dart Coverage Total Hit
Test: lcov.info Lines: 68.6 % 51 35
Test Date: 2026-11-14 15:04:37 Functions: - 0 0

            Line data    Source code
       1              : // Copyright 2023 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/herald/app_sorting.dart';
       5              : import 'package:app_finance/_classes/storage/app_data.dart';
       6              : import 'package:app_finance/_classes/herald/app_locale.dart';
       7              : import 'package:app_finance/_classes/structure/account_app_data.dart';
       8              : import 'package:app_finance/_classes/structure/currency/exchange.dart';
       9              : import 'package:app_finance/_configs/theme_helper.dart';
      10              : import 'package:app_finance/_classes/structure/navigation/app_route.dart';
      11              : import 'package:app_finance/design/wrapper/background_wrapper.dart';
      12              : import 'package:app_finance/pages/_interfaces/abstract_page_state.dart';
      13              : import 'package:app_finance/pages/account/widgets/account_line_widget.dart';
      14              : import 'package:app_finance/design/generic/base_header_widget.dart';
      15              : import 'package:app_finance/design/generic/base_swipe_widget.dart';
      16              : import 'package:app_finance/design/wrapper/tap_widget.dart';
      17              : import 'package:app_finance/pages/account/widgets/header_widget.dart';
      18              : import 'package:material_ui/material_ui.dart';
      19              : import 'package:provider/provider.dart';
      20              : 
      21              : class AccountPage extends StatefulWidget {
      22              :   final String? search;
      23              : 
      24            2 :   const AccountPage({
      25              :     super.key,
      26              :     this.search,
      27              :   });
      28              : 
      29            1 :   @override
      30            1 :   AccountPageState createState() => AccountPageState();
      31              : }
      32              : 
      33              : class AccountPageState extends AbstractPageState<AccountPage> {
      34            1 :   AppDataGetter _getItems() {
      35            2 :     if (widget.search != null) {
      36            0 :       final scope = state.getList(AppDataType.accounts).where((e) => e.title.toString().startsWith(widget.search!));
      37            0 :       final ex = Exchange(store: super.state);
      38              :       return (
      39            0 :         total: scope.fold(0.0, (v, e) => v + ex.reform(e.details, e.currency, ex.getDefaultCurrency())),
      40            0 :         list: scope.toList(),
      41            0 :         stream: state.getStream(AppDataType.accounts, filter: (e) => !e.title.toString().startsWith(widget.search!))
      42              :       );
      43              :     }
      44            2 :     return state.get(AppDataType.accounts);
      45              :   }
      46              : 
      47            1 :   @override
      48              :   String getTitle() {
      49            2 :     if (widget.search != null) {
      50            0 :       return AppLocale.labels.search(widget.search!);
      51              :     }
      52            2 :     return AppLocale.labels.accountHeadline;
      53              :   }
      54              : 
      55            1 :   @override
      56            2 :   String getButtonName() => AppLocale.labels.addAccountTooltip;
      57              : 
      58            1 :   @override
      59              :   Widget buildButton(BuildContext context, BoxConstraints constraints) {
      60            1 :     NavigatorState nav = Navigator.of(context);
      61            1 :     return FloatingActionButton(
      62              :       heroTag: 'account_page',
      63            0 :       onPressed: () => nav.pushNamed(AppRoute.accountAddRoute),
      64            1 :       tooltip: getButtonName(),
      65              :       child: const Icon(Icons.add),
      66              :     );
      67              :   }
      68              : 
      69            1 :   @override
      70              :   Widget buildContent(BuildContext context, BoxConstraints constraints) {
      71            1 :     final items = _getItems();
      72            1 :     final sorting = Provider.of<AppSorting>(context, listen: true);
      73            2 :     items.list.sort(sorting.getSortFunction(context));
      74            1 :     final width = ThemeHelper.getWidth(context, 4, constraints);
      75            1 :     final indent = ThemeHelper.getIndent();
      76            1 :     final widthCount = ThemeHelper.getWidthCount(constraints, context);
      77            1 :     return Padding(
      78            1 :       padding: EdgeInsets.all(indent),
      79            1 :       child: Column(
      80            1 :         children: [
      81            1 :           BaseHeaderWidget(
      82              :             route: AppRoute.homeRoute,
      83            2 :             tooltip: AppLocale.labels.homeTooltip,
      84              :             width: width,
      85              :             total: items.total,
      86            5 :             title: '${AppLocale.labels.accountHeadline}, ${AppLocale.labels.total}',
      87              :             sortRoute: AppRoute.sortingRoute,
      88              :           ),
      89              :           ThemeHelper.hIndent,
      90            1 :           if (widthCount > 2) HeaderWidget(count: widthCount, width: width),
      91            1 :           Expanded(
      92            1 :             child: ListView.separated(
      93              :               scrollDirection: Axis.vertical,
      94              :               shrinkWrap: true,
      95            2 :               itemCount: items.list.length + 1,
      96            0 :               separatorBuilder: (_, index) => Divider(height: indent),
      97            1 :               itemBuilder: (BuildContext context, index) {
      98            2 :                 if (index >= items.list.length) {
      99              :                   return ThemeHelper.formEndBox;
     100              :                 }
     101            0 :                 AccountAppData item = items.list[index];
     102            0 :                 return BackgroundWrapper(
     103              :                   index: index,
     104            0 :                   child: BaseSwipeWidget(
     105              :                     routePath: AppRoute.accountEditRoute,
     106            0 :                     uuid: item.uuid!,
     107            0 :                     child: TapWidget(
     108              :                       tooltip: '',
     109            0 :                       route: RouteSettings(
     110              :                         name: AppRoute.accountViewRoute,
     111            0 :                         arguments: {routeArguments.uuid: item.uuid},
     112              :                       ),
     113            0 :                       child: AccountLineWidget(
     114              :                         item: item,
     115              :                         width: width,
     116              :                         count: widthCount,
     117              :                       ),
     118              :                     ),
     119              :                   ),
     120              :                 );
     121              :               },
     122              :             ),
     123              :           ),
     124              :         ],
     125              :       ),
     126              :     );
     127              :   }
     128              : }
        

Generated by: LCOV version 2.0-1