LCOV - code coverage report
Current view: top level - lib/_classes/structure - currency_app_data.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 20 32 62.5 %
Date: 2024-10-04 11:12:13 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/structure/abstract_app_data.dart';
       5             : import 'package:app_finance/_classes/storage/app_data.dart';
       6             : import 'package:app_finance/_ext/date_time_ext.dart';
       7             : import 'package:flutter_currency_picker/flutter_currency_picker.dart';
       8             : 
       9             : class CurrencyAppData extends AbstractAppData {
      10             :   Currency? currencyFrom;
      11             : 
      12           1 :   CurrencyAppData({
      13             :     super.title = '',
      14             :     super.uuid = '',
      15             :     super.details = 1.0,
      16             :     super.description,
      17             :     this.currencyFrom,
      18             :     super.currency,
      19             :     super.hidden,
      20             :     super.updatedAt,
      21             :     super.createdAt,
      22             :   }) {
      23           3 :     super.description = DateTime.now().toString();
      24             :   }
      25             : 
      26           1 :   @override
      27             :   String getClassName() => 'CurrencyAppData';
      28             : 
      29           1 :   @override
      30             :   AppDataType getType() => AppDataType.currencies;
      31             : 
      32           1 :   @override
      33             :   CurrencyAppData clone() {
      34           1 :     return CurrencyAppData(
      35           1 :       title: super.title,
      36           1 :       uuid: super.uuid,
      37           1 :       details: super.details,
      38           1 :       currency: super.currency,
      39           1 :       currencyFrom: currencyFrom,
      40           1 :       hidden: super.hidden,
      41             :     );
      42             :   }
      43             : 
      44           0 :   factory CurrencyAppData.fromJson(Map<String, dynamic> json) {
      45           0 :     return CurrencyAppData(
      46           0 :       title: json['title'],
      47           0 :       uuid: json['uuid'],
      48           0 :       details: 0.0 + json['details'],
      49           0 :       updatedAt: DateTime.parse(json['updatedAt']),
      50           0 :       createdAt: DateTime.parse(json['createdAt']),
      51           0 :       currency: CurrencyProvider.find(json['currency']),
      52           0 :       currencyFrom: CurrencyProvider.find(json['currencyFrom']),
      53           0 :       hidden: json['hidden'],
      54             :     );
      55             :   }
      56             : 
      57           1 :   @override
      58           1 :   Map<String, dynamic> toJson() => {
      59           1 :         ...super.toJson(),
      60           2 :         'currencyFrom': currencyFrom?.code,
      61             :       };
      62             : 
      63           0 :   String get detailsFormatted => (super.details as double).toCurrency(currency: currency, withPattern: false);
      64             : 
      65           0 :   String get descriptionFormatted => DateTime.parse(super.description ?? '').yMEd();
      66             : 
      67           1 :   @override
      68           3 :   String get title => '${currencyFrom?.code ?? '?'} -> ${currency?.code ?? '?'}';
      69             : 
      70           1 :   @override
      71           3 :   String get uuid => '${currencyFrom?.code ?? '?'}-${currency?.code ?? '?'}';
      72             : }

Generated by: LCOV version 1.14