2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2023-08-15 00:47:25 +00:00
|
|
|
import 'package:cw_core/hive_type_ids.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/keyable.dart';
|
2023-08-15 00:47:25 +00:00
|
|
|
import 'package:hive/hive.dart';
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
part 'contact.g.dart';
|
|
|
|
|
2021-01-15 17:41:30 +00:00
|
|
|
@HiveType(typeId: Contact.typeId)
|
2020-09-07 15:13:39 +00:00
|
|
|
class Contact extends HiveObject with Keyable {
|
2024-11-07 01:26:14 +00:00
|
|
|
Contact({required this.name, required this.address, CryptoCurrency? type, DateTime? lastChange})
|
|
|
|
: lastChange = lastChange ?? DateTime.now() {
|
2022-10-12 17:09:57 +00:00
|
|
|
if (type != null) {
|
|
|
|
raw = type.raw;
|
|
|
|
}
|
|
|
|
}
|
2020-01-08 12:26:34 +00:00
|
|
|
|
2023-08-15 00:47:25 +00:00
|
|
|
static const typeId = CONTACT_TYPE_ID;
|
2020-01-04 19:31:52 +00:00
|
|
|
static const boxName = 'Contacts';
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(0, defaultValue: '')
|
2020-01-04 19:31:52 +00:00
|
|
|
String name;
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(1, defaultValue: '')
|
2020-01-04 19:31:52 +00:00
|
|
|
String address;
|
|
|
|
|
2022-11-04 19:55:21 +00:00
|
|
|
@HiveField(2, defaultValue: 0)
|
2022-10-12 17:09:57 +00:00
|
|
|
late int raw;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2024-11-07 01:26:14 +00:00
|
|
|
@HiveField(3)
|
|
|
|
DateTime lastChange;
|
|
|
|
|
2020-01-04 19:31:52 +00:00
|
|
|
CryptoCurrency get type => CryptoCurrency.deserialize(raw: raw);
|
|
|
|
|
2020-09-07 15:13:39 +00:00
|
|
|
@override
|
|
|
|
dynamic get keyIndex => key;
|
|
|
|
|
2020-07-06 20:09:03 +00:00
|
|
|
@override
|
|
|
|
bool operator ==(Object o) => o is Contact && o.key == key;
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode => key.hashCode;
|
|
|
|
|
2024-11-07 01:26:14 +00:00
|
|
|
void updateCryptoCurrency({required CryptoCurrency currency}) => raw = currency.raw;
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|