LCOV - code coverage report
Current view: top level - lib/pages/account - account_add_page.dart Coverage Total Hit
Test: lcov.info Lines: 0.8 % 125 1
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_design.dart';
       5              : import 'package:app_finance/_classes/herald/app_locale.dart';
       6              : import 'package:app_finance/_classes/structure/account_app_data.dart';
       7              : import 'package:app_finance/_configs/account_type.dart';
       8              : import 'package:app_finance/_classes/controller/focus_controller.dart';
       9              : import 'package:app_finance/_classes/storage/app_preferences.dart';
      10              : import 'package:app_finance/_configs/theme_helper.dart';
      11              : import 'package:app_finance/_ext/build_context_ext.dart';
      12              : import 'package:app_finance/design/form/checkbox_input.dart';
      13              : import 'package:app_finance/design/wrapper/input_wrapper.dart';
      14              : import 'package:app_finance/design/wrapper/text_wrapper.dart';
      15              : import 'package:app_finance/pages/_interfaces/abstract_add_page.dart';
      16              : import 'package:app_finance/design/form/date_time_input.dart';
      17              : import 'package:app_finance/design/button/full_sized_button_widget.dart';
      18              : import 'package:app_finance/design/form/simple_input.dart';
      19              : import 'package:app_finance/design/wrapper/row_widget.dart';
      20              : import 'package:app_finance/design/wrapper/single_scroll_wrapper.dart';
      21              : import 'package:material_ui/material_ui.dart';
      22              : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
      23              : 
      24              : class AccountAddPage extends AbstractAddPage {
      25              :   final String? title;
      26              :   final String? description;
      27              :   final String? type;
      28              :   final Currency? currency;
      29              :   final DateTime? validTillDate;
      30              :   final double? balance;
      31              :   final IconData? icon;
      32              :   final MaterialColor? color;
      33              : 
      34            2 :   const AccountAddPage({
      35              :     super.key,
      36              :     this.title,
      37              :     this.description,
      38              :     this.type,
      39              :     this.currency,
      40              :     this.validTillDate,
      41              :     this.balance,
      42              :     this.icon,
      43              :     this.color,
      44              :   });
      45              : 
      46            0 :   @override
      47            0 :   AccountAddPageState createState() => AccountAddPageState();
      48              : }
      49              : 
      50              : class AccountAddPageState<T extends AccountAddPage> extends AbstractAddPageState<T> {
      51              :   late FocusController focus;
      52              :   late TextEditingController title;
      53              :   late TextEditingController description;
      54              :   String? type;
      55              :   Currency? currency;
      56              :   DateTime? validTillDate;
      57              :   DateTime balanceUpdateDate = DateTime.now();
      58              :   late TextEditingController balance;
      59              :   IconData? icon;
      60              :   MaterialColor? color;
      61              :   bool skip = false;
      62              : 
      63            0 :   @override
      64              :   void initState() {
      65            0 :     focus = FocusController();
      66            0 :     title = TextEditingController(text: widget.title);
      67            0 :     description = TextEditingController(text: widget.description);
      68            0 :     type = widget.type;
      69            0 :     validTillDate = widget.validTillDate;
      70            0 :     final currencyId = AppPreferences.get(AppPreferences.prefCurrency);
      71            0 :     currency = widget.currency ?? CurrencyProvider.find(currencyId);
      72            0 :     balance = TextEditingController(text: widget.balance != null ? widget.balance!.toString() : '');
      73            0 :     icon = widget.icon;
      74            0 :     color = widget.color;
      75            0 :     super.initState();
      76              :   }
      77              : 
      78            0 :   @override
      79              :   void dispose() {
      80            0 :     title.dispose();
      81            0 :     description.dispose();
      82            0 :     balance.dispose();
      83            0 :     focus.dispose();
      84            0 :     super.dispose();
      85              :   }
      86              : 
      87            0 :   @override
      88            0 :   String getTitle() => AppLocale.labels.createAccountHeader;
      89              : 
      90            0 :   @override
      91              :   bool hasFormErrors() {
      92            0 :     setState(() => hasError = type == null || type?.isEmpty == true || title.text.isEmpty || currency == null);
      93            0 :     return hasError;
      94              :   }
      95              : 
      96            0 :   @override
      97              :   void updateStorage() {
      98            0 :     if (currency != null) {
      99            0 :       CurrencyProvider.pin(currency!);
     100              :     }
     101            0 :     state.add(AccountAppData(
     102            0 :       title: title.text,
     103            0 :       type: type ?? AppAccountType.cash.toString(),
     104            0 :       description: description.text,
     105            0 :       details: double.tryParse(balance.text) ?? 0.0,
     106              :       progress: 1.0,
     107            0 :       color: color ?? Colors.red,
     108            0 :       currency: currency,
     109              :       hidden: false,
     110            0 :       icon: icon,
     111            0 :       closedAt: validTillDate,
     112            0 :       createdAt: balanceUpdateDate,
     113            0 :       skip: skip,
     114              :     ));
     115              :   }
     116              : 
     117            0 :   @override
     118            0 :   String getButtonName() => AppLocale.labels.createAccountTooltip;
     119              : 
     120            0 :   @override
     121              :   Widget buildButton(BuildContext context, BoxConstraints constraints) {
     122            0 :     NavigatorState nav = Navigator.of(context);
     123            0 :     return FullSizedButtonWidget(
     124              :       constraints: constraints,
     125            0 :       controller: focus,
     126            0 :       onPressed: () => triggerActionButton(nav),
     127            0 :       title: getButtonName(),
     128              :       icon: Icons.save,
     129              :     );
     130              :   }
     131              : 
     132            0 :   @override
     133              :   Widget buildContent(BuildContext context, BoxConstraints constraints) {
     134            0 :     final TextTheme textTheme = context.textTheme;
     135            0 :     double indent = ThemeHelper.getIndent(2);
     136            0 :     double width = ThemeHelper.getWidth(context, 6, constraints);
     137              : 
     138            0 :     return SingleScrollWrapper(
     139            0 :       controller: focus,
     140            0 :       child: Container(
     141            0 :         margin: EdgeInsets.fromLTRB(indent, indent, indent, 240),
     142            0 :         child: Column(
     143            0 :           crossAxisAlignment: AppDesign.getAlignment(),
     144            0 :           children: [
     145            0 :             InputWrapper.select(
     146              :               isRequired: true,
     147            0 :               value: type,
     148            0 :               title: AppLocale.labels.accountType,
     149            0 :               tooltip: AppLocale.labels.accountTypeTooltip,
     150            0 :               showError: hasError && type == null,
     151            0 :               options: AccountType.getList(),
     152            0 :               onChange: (value) => setState(() => type = value),
     153              :             ),
     154            0 :             InputWrapper.text(
     155              :               isRequired: true,
     156            0 :               controller: title,
     157            0 :               title: AppLocale.labels.title,
     158            0 :               tooltip: AppLocale.labels.titleAccountTooltip,
     159            0 :               showError: hasError && title.text.isEmpty,
     160              :             ),
     161            0 :             RowWidget(
     162              :               indent: indent,
     163            0 :               maxWidth: width + indent,
     164              :               chunk: const [80, 80, null],
     165            0 :               children: [
     166            0 :                 [
     167            0 :                   InputWrapper.icon(
     168            0 :                     value: icon,
     169            0 :                     title: AppLocale.labels.icon,
     170            0 :                     onChange: (value) => setState(() => icon = value),
     171              :                   ),
     172              :                 ],
     173            0 :                 [
     174            0 :                   InputWrapper.color(
     175            0 :                     value: color,
     176            0 :                     title: AppLocale.labels.color,
     177            0 :                     onChange: (value) => setState(() => color = value),
     178              :                   ),
     179              :                 ],
     180            0 :                 [
     181            0 :                   InputWrapper.text(
     182            0 :                     controller: description,
     183            0 :                     title: AppLocale.labels.details,
     184            0 :                     tooltip: AppLocale.labels.detailsTooltip,
     185              :                   ),
     186              :                 ],
     187              :               ],
     188              :             ),
     189            0 :             InputWrapper.currency(
     190              :               isRequired: true,
     191            0 :               showError: hasError && currency == null,
     192            0 :               value: currency,
     193            0 :               title: AppLocale.labels.currency,
     194            0 :               tooltip: AppLocale.labels.currencyTooltip,
     195            0 :               onChange: (value) => setState(() => currency = value),
     196              :             ),
     197            0 :             if (!AccountType.contains(type ?? '', [AppAccountType.account, AppAccountType.cash]))
     198            0 :               InputWrapper(
     199              :                 type: NamedInputType.ymSelector,
     200            0 :                 title: AppLocale.labels.validTillDate,
     201            0 :                 value: validTillDate,
     202            0 :                 onChange: (value) => setState(() => validTillDate = value),
     203              :               ),
     204            0 :             InputWrapper.text(
     205            0 :               title: AppLocale.labels.balance,
     206            0 :               tooltip: AppLocale.labels.balanceTooltip,
     207            0 :               controller: balance,
     208              :               inputType: const TextInputType.numberWithOptions(decimal: true),
     209            0 :               formatter: [
     210            0 :                 SimpleInputFormatter.filterDouble,
     211              :               ],
     212              :             ),
     213            0 :             CheckboxInput(
     214            0 :               label: AppLocale.labels.skipFromTotals,
     215            0 :               value: skip,
     216            0 :               onChanged: (value) => setState(() => skip = value),
     217              :               constraints: constraints,
     218              :             ),
     219            0 :             ThemeHelper.hIndent2x,
     220            0 :             RowWidget(
     221              :               indent: indent,
     222            0 :               maxWidth: width + indent,
     223              :               chunk: const [null, 20],
     224            0 :               children: [
     225            0 :                 [
     226            0 :                   TextWrapper(
     227            0 :                     AppLocale.labels.balanceDate,
     228            0 :                     style: textTheme.bodyLarge,
     229              :                   ),
     230              :                 ],
     231            0 :                 [
     232            0 :                   Tooltip(
     233            0 :                     message: AppLocale.labels.balanceDateTooltip,
     234              :                     child: const Icon(Icons.info_outline),
     235              :                   ),
     236              :                 ]
     237              :               ],
     238              :             ),
     239            0 :             DateTimeInput(
     240              :               width: width,
     241            0 :               value: balanceUpdateDate,
     242            0 :               setState: (value) => setState(() => balanceUpdateDate = value),
     243              :             ),
     244            0 :             ThemeHelper.hIndent2x,
     245              :           ],
     246              :         ),
     247              :       ),
     248              :     );
     249              :   }
     250              : }
        

Generated by: LCOV version 2.0-1