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 'dart:convert'; 5 : 6 : import 'package:flutter_currency_picker/flutter_currency_picker.dart'; 7 : 8 : class TransactionLogData<T> { 9 : final String name; 10 : final T changedFrom; 11 : final T changedTo; 12 : final String? ref; 13 : final DateTime _time; 14 : Currency? currency; 15 : 16 1 : TransactionLogData({ 17 : DateTime? timestamp, 18 : required this.name, 19 : this.ref, 20 : this.currency, 21 : required this.changedFrom, 22 : required this.changedTo, 23 0 : }) : _time = timestamp ?? DateTime.now(); 24 : 25 2 : DateTime get timestamp => _time; 26 : 27 0 : double get delta => (double.tryParse(changedTo.toString()) ?? 0.0) - (double.tryParse(changedFrom.toString()) ?? 0.0); 28 : 29 1 : TransactionLogData clone() { 30 1 : return TransactionLogData( 31 1 : name: name, 32 1 : changedFrom: changedFrom, 33 1 : changedTo: changedTo, 34 1 : ref: ref, 35 1 : timestamp: timestamp, 36 1 : currency: currency, 37 : ); 38 : } 39 : 40 0 : @override 41 : String toString() { 42 0 : return json.encode({ 43 0 : 'ref': ref, 44 0 : 'timestamp': timestamp.toString(), 45 0 : 'changedFrom': changedFrom, 46 0 : 'changedTo': changedTo, 47 0 : 'currency': currency?.code, 48 : }); 49 : } 50 : }