LCOV - code coverage report
Current view: top level - lib/pages/currency - currency_add_page.dart Coverage Total Hit
Test: lcov.info Lines: 1.6 % 61 1
Test Date: 2026-11-14 15:04:37 Functions: - 0 0

            Line data    Source code
       1              : // Copyright 2024 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/focus_controller.dart';
       5              : import 'package:app_finance/_classes/herald/app_design.dart';
       6              : import 'package:app_finance/_classes/herald/app_locale.dart';
       7              : import 'package:app_finance/_classes/structure/currency_app_data.dart';
       8              : import 'package:app_finance/_configs/theme_helper.dart';
       9              : import 'package:app_finance/design/form/simple_input.dart';
      10              : import 'package:app_finance/design/wrapper/input_wrapper.dart';
      11              : import 'package:app_finance/design/wrapper/single_scroll_wrapper.dart';
      12              : import 'package:app_finance/pages/_interfaces/abstract_add_page.dart';
      13              : import 'package:material_ui/material_ui.dart';
      14              : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
      15              : 
      16              : class CurrencyAddPage extends AbstractAddPage {
      17            2 :   const CurrencyAddPage({super.key});
      18              : 
      19            0 :   @override
      20            0 :   CurrencyAddPageState createState() => CurrencyAddPageState();
      21              : }
      22              : 
      23              : class CurrencyAddPageState extends AbstractAddPageState<CurrencyAddPage> {
      24              :   late FocusController focus;
      25              :   Currency? currencyFrom;
      26              :   Currency? currencyTo;
      27              :   late TextEditingController conversion;
      28              : 
      29            0 :   @override
      30              :   void initState() {
      31            0 :     focus = FocusController();
      32            0 :     conversion = TextEditingController(text: '');
      33            0 :     super.initState();
      34              :   }
      35              : 
      36            0 :   @override
      37              :   void dispose() {
      38            0 :     focus.dispose();
      39            0 :     conversion.dispose();
      40            0 :     super.dispose();
      41              :   }
      42              : 
      43            0 :   @override
      44            0 :   String getTitle() => AppLocale.labels.currencyAddHeadline;
      45              : 
      46            0 :   @override
      47            0 :   String getButtonName() => AppLocale.labels.currencyAddTooltip;
      48              : 
      49            0 :   @override
      50              :   bool hasFormErrors() {
      51            0 :     setState(() => hasError = currencyFrom == null ||
      52            0 :         currencyTo == null ||
      53            0 :         currencyFrom == currencyTo ||
      54            0 :         conversion.text.isEmpty ||
      55            0 :         double.tryParse(conversion.text) == 1.0);
      56            0 :     return hasError;
      57              :   }
      58              : 
      59            0 :   @override
      60              :   void updateStorage() {
      61            0 :     final exchange = CurrencyAppData(
      62            0 :       currency: currencyTo,
      63            0 :       currencyFrom: currencyFrom,
      64            0 :       details: double.tryParse(conversion.text) ?? 1.0,
      65              :     );
      66            0 :     state.update(exchange.uuid, exchange, true);
      67              :   }
      68              : 
      69            0 :   @override
      70              :   Widget buildButton(BuildContext context, BoxConstraints constraints) {
      71            0 :     NavigatorState nav = Navigator.of(context);
      72            0 :     return FloatingActionButton(
      73              :       heroTag: 'currency_page_add',
      74            0 :       onPressed: () => triggerActionButton(nav),
      75            0 :       tooltip: getButtonName(),
      76              :       child: const Icon(Icons.save),
      77              :     );
      78              :   }
      79              : 
      80            0 :   @override
      81              :   Widget buildContent(BuildContext context, BoxConstraints constraints) {
      82            0 :     final indent = ThemeHelper.getIndent();
      83            0 :     return SingleScrollWrapper(
      84            0 :       controller: focus,
      85            0 :       child: Padding(
      86            0 :         padding: EdgeInsets.all(indent),
      87            0 :         child: Column(
      88            0 :           crossAxisAlignment: AppDesign.getAlignment(),
      89            0 :           children: [
      90            0 :             InputWrapper.currency(
      91              :               isRequired: true,
      92            0 :               showError: hasError && currencyFrom == null,
      93            0 :               value: currencyFrom,
      94            0 :               title: '${AppLocale.labels.currency} (${AppLocale.labels.from})',
      95            0 :               tooltip: AppLocale.labels.currencyTooltip,
      96            0 :               onChange: (value) => setState(() => currencyFrom = value),
      97              :             ),
      98            0 :             InputWrapper.currency(
      99              :               isRequired: true,
     100            0 :               showError: hasError && (currencyTo == null || currencyFrom == currencyTo),
     101            0 :               value: currencyTo,
     102            0 :               title: '${AppLocale.labels.currency} (${AppLocale.labels.to})',
     103            0 :               tooltip: AppLocale.labels.currencyTooltip,
     104            0 :               onChange: (value) => setState(() => currencyTo = value),
     105              :             ),
     106            0 :             InputWrapper.text(
     107            0 :               title: AppLocale.labels.currencyExchange(currencyFrom?.code ?? '?', currencyTo?.code ?? '?'),
     108            0 :               tooltip: AppLocale.labels.conversion,
     109              :               isRequired: true,
     110            0 :               showError: hasError && (conversion.text.isEmpty || double.tryParse(conversion.text) == 1.0),
     111            0 :               controller: conversion,
     112              :               inputType: const TextInputType.numberWithOptions(decimal: true),
     113            0 :               formatter: [
     114            0 :                 SimpleInputFormatter.filterDouble,
     115              :               ],
     116              :             ),
     117              :             ThemeHelper.formEndBox,
     118              :           ],
     119              :         ),
     120              :       ),
     121              :     );
     122              :   }
     123              : }
        

Generated by: LCOV version 2.0-1