LCOV - code coverage report
Current view: top level - lib/_classes/structure - account_app_data.dart Coverage Total Hit
Test: lcov.info Lines: 64.8 % 54 35
Test Date: 2026-11-14 15:08:11 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_locale.dart';
       5              : import 'package:app_finance/_classes/structure/abstract_app_data.dart';
       6              : import 'package:app_finance/_classes/storage/app_data.dart';
       7              : import 'package:app_finance/_configs/account_type.dart';
       8              : import 'package:app_finance/_ext/date_time_ext.dart';
       9              : import 'package:app_finance/_ext/int_ext.dart';
      10              : import 'package:material_ui/material_ui.dart';
      11              : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
      12              : 
      13              : class AccountAppData extends AbstractAppData {
      14              :   DateTime _closedAt;
      15              :   String type;
      16              : 
      17            1 :   AccountAppData({
      18              :     required super.title,
      19              :     required this.type,
      20              :     super.uuid,
      21              :     super.details,
      22              :     super.progress = 0.0,
      23              :     super.description,
      24              :     super.color,
      25              :     super.icon,
      26              :     super.currency,
      27              :     super.updatedAt,
      28              :     super.createdAt,
      29              :     super.createdAtFormatted,
      30              :     DateTime? closedAt,
      31              :     String? closedAtFormatted,
      32              :     super.hidden,
      33              :     super.skip,
      34            1 :   }) : _closedAt = closedAt ?? (closedAtFormatted != null ? DateTime.parse(closedAtFormatted) : DateTime.now());
      35              : 
      36            1 :   @override
      37              :   String getClassName() => 'AccountAppData';
      38              : 
      39            1 :   @override
      40              :   AppDataType getType() => AppDataType.accounts;
      41              : 
      42            1 :   @override
      43              :   AccountAppData clone() {
      44            1 :     return AccountAppData(
      45            1 :       uuid: super.uuid,
      46            1 :       title: super.title,
      47            1 :       type: type,
      48            1 :       details: super.details,
      49            1 :       progress: super.progress,
      50            1 :       description: super.description,
      51            1 :       color: super.color,
      52            1 :       icon: super.icon,
      53            1 :       currency: super.currency,
      54            1 :       createdAt: super.createdAt,
      55            1 :       closedAt: closedAt,
      56            1 :       hidden: super.hidden,
      57            1 :       skip: super.skip,
      58              :     );
      59              :   }
      60              : 
      61            0 :   factory AccountAppData.fromJson(Map<String, dynamic> json) {
      62            0 :     return AccountAppData(
      63            0 :       uuid: json['uuid'],
      64            0 :       title: json['title'],
      65            0 :       type: json['type'],
      66            0 :       details: 0.0 + json['details'],
      67            0 :       progress: 0.0 + json['progress'],
      68            0 :       description: json['description'],
      69            0 :       color: json['color'] != null ? MaterialColor(json['color'], const <int, Color>{}) : null,
      70            0 :       icon: (json['icon'] as int?)?.toIcon(),
      71            0 :       currency: CurrencyProvider.find(json['currency']),
      72            0 :       createdAt: DateTime.parse(json['createdAt']),
      73            0 :       updatedAt: DateTime.parse(json['updatedAt']),
      74            0 :       closedAt: DateTime.parse(json['closedAt']),
      75            0 :       hidden: json['hidden'],
      76            0 :       skip: json['skip'] ?? false,
      77              :     );
      78              :   }
      79              : 
      80            1 :   @override
      81            1 :   Map<String, dynamic> toJson() => {
      82            1 :         ...super.toJson(),
      83            2 :         'type': type,
      84            3 :         'closedAt': closedAt.toIso8601String(),
      85              :       };
      86              : 
      87              :   // ignore: unnecessary_getters_setters
      88            2 :   DateTime get closedAt => _closedAt;
      89            0 :   set closedAt(DateTime value) => _closedAt = value;
      90            3 :   String get closedAtFormatted => _closedAt.yearMonth();
      91            0 :   set closedAtFormatted(String value) => _closedAt = DateTime.parse(value);
      92              : 
      93            4 :   String get detailsFormatted => (super.details as double).toCurrency(currency: currency, withPattern: false);
      94              : 
      95            1 :   @override
      96              :   Widget? get error {
      97              :     String? error;
      98            5 :     final isCredit = [AppAccountType.credit.toString(), AppAccountType.creditCard.toString()].contains(type);
      99            5 :     final isCard = [AppAccountType.debitCard.toString(), AppAccountType.creditCard.toString()].contains(type);
     100            2 :     if (details < 0 && !isCredit) {
     101            0 :       error = AppLocale.labels.errorNegative;
     102            3 :     } else if (isCard && closedAt.isBefore(DateTime.now())) {
     103            2 :       error = AppLocale.labels.errorExpired;
     104              :     }
     105              : 
     106              :     return error == null
     107              :         ? null
     108            1 :         : Tooltip(
     109              :             message: error,
     110            1 :             child: Icon(Icons.warning, semanticLabel: error),
     111              :           );
     112              :   }
     113              : }
        

Generated by: LCOV version 2.0-1