2023-02-02 21:37:59 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2023-04-02 19:48:14 +00:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2023-02-03 19:22:21 +00:00
|
|
|
import 'package:isar/isar.dart';
|
2023-03-01 21:52:13 +00:00
|
|
|
import 'package:stackwallet/db/isar/main_db.dart';
|
2023-02-02 21:37:59 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
2023-03-21 23:18:07 +00:00
|
|
|
import 'package:stackwallet/pages/receive_view/addresses/address_tag.dart';
|
2023-04-02 19:48:14 +00:00
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
2023-02-02 21:37:59 +00:00
|
|
|
import 'package:stackwallet/utilities/clipboard_interface.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2023-04-02 19:48:14 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
2023-02-02 21:37:59 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
|
|
|
|
2023-02-03 19:22:21 +00:00
|
|
|
class AddressCard extends StatefulWidget {
|
2023-02-02 21:37:59 +00:00
|
|
|
const AddressCard({
|
|
|
|
Key? key,
|
2023-03-07 13:48:25 +00:00
|
|
|
required this.addressId,
|
2023-02-02 21:37:59 +00:00
|
|
|
required this.walletId,
|
|
|
|
required this.coin,
|
2023-03-21 23:18:07 +00:00
|
|
|
this.onPressed,
|
2023-02-02 21:37:59 +00:00
|
|
|
this.clipboard = const ClipboardWrapper(),
|
|
|
|
}) : super(key: key);
|
|
|
|
|
2023-03-07 13:48:25 +00:00
|
|
|
final int addressId;
|
2023-02-02 21:37:59 +00:00
|
|
|
final String walletId;
|
|
|
|
final Coin coin;
|
|
|
|
final ClipboardInterface clipboard;
|
2023-03-21 23:18:07 +00:00
|
|
|
final VoidCallback? onPressed;
|
2023-02-02 21:37:59 +00:00
|
|
|
|
2023-02-03 19:22:21 +00:00
|
|
|
@override
|
|
|
|
State<AddressCard> createState() => _AddressCardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AddressCardState extends State<AddressCard> {
|
2023-04-02 19:48:14 +00:00
|
|
|
final isDesktop = Util.isDesktop;
|
|
|
|
|
2023-02-03 19:22:21 +00:00
|
|
|
late Stream<AddressLabel?> stream;
|
2023-03-07 13:48:25 +00:00
|
|
|
late final Address address;
|
2023-02-03 19:22:21 +00:00
|
|
|
|
|
|
|
AddressLabel? label;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2023-03-07 13:48:25 +00:00
|
|
|
address = MainDB.instance.isar.addresses
|
|
|
|
.where()
|
|
|
|
.idEqualTo(widget.addressId)
|
|
|
|
.findFirstSync()!;
|
|
|
|
|
|
|
|
label = MainDB.instance.getAddressLabelSync(widget.walletId, address.value);
|
2023-02-03 19:22:21 +00:00
|
|
|
Id? id = label?.id;
|
|
|
|
if (id == null) {
|
|
|
|
label = AddressLabel(
|
|
|
|
walletId: widget.walletId,
|
2023-03-07 13:48:25 +00:00
|
|
|
addressString: address.value,
|
2023-02-03 19:22:21 +00:00
|
|
|
value: "",
|
2023-03-21 16:01:04 +00:00
|
|
|
tags: address.subType == AddressSubType.receiving
|
|
|
|
? ["receiving"]
|
|
|
|
: address.subType == AddressSubType.change
|
|
|
|
? ["change"]
|
|
|
|
: null,
|
2023-02-03 19:22:21 +00:00
|
|
|
);
|
|
|
|
id = MainDB.instance.putAddressLabelSync(label!);
|
|
|
|
}
|
|
|
|
stream = MainDB.instance.watchAddressLabel(id: id);
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2023-02-02 21:37:59 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return RoundedWhiteContainer(
|
2023-03-21 23:18:07 +00:00
|
|
|
onPressed: widget.onPressed,
|
2023-02-03 19:22:21 +00:00
|
|
|
child: StreamBuilder<AddressLabel?>(
|
2023-03-21 23:18:07 +00:00
|
|
|
stream: stream,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
label = snapshot.data!;
|
|
|
|
}
|
2023-02-03 19:22:21 +00:00
|
|
|
|
2023-04-02 19:48:14 +00:00
|
|
|
return ConditionalParent(
|
|
|
|
condition: isDesktop,
|
|
|
|
builder: (child) => Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
SvgPicture.asset(
|
|
|
|
Assets.svg.iconFor(coin: widget.coin),
|
|
|
|
width: 32,
|
|
|
|
height: 32,
|
2023-02-02 21:37:59 +00:00
|
|
|
),
|
2023-02-03 19:22:21 +00:00
|
|
|
const SizedBox(
|
2023-04-02 19:48:14 +00:00
|
|
|
width: 12,
|
2023-02-02 21:37:59 +00:00
|
|
|
),
|
2023-04-02 19:48:14 +00:00
|
|
|
Expanded(
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
if (label!.value.isNotEmpty)
|
|
|
|
Text(
|
|
|
|
label!.value,
|
|
|
|
style: STextStyles.itemSubtitle(context),
|
|
|
|
textAlign: TextAlign.left,
|
2023-03-22 19:28:28 +00:00
|
|
|
),
|
2023-04-02 19:48:14 +00:00
|
|
|
if (label!.value.isNotEmpty)
|
|
|
|
SizedBox(
|
|
|
|
height: isDesktop ? 2 : 8,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
address.value,
|
|
|
|
style: STextStyles.itemSubtitle12(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
2023-03-21 23:18:07 +00:00
|
|
|
),
|
2023-04-02 19:48:14 +00:00
|
|
|
if (label!.tags != null && label!.tags!.isNotEmpty)
|
|
|
|
Wrap(
|
|
|
|
spacing: 10,
|
|
|
|
runSpacing: 10,
|
|
|
|
children: label!.tags!
|
|
|
|
.map(
|
|
|
|
(e) => AddressTag(
|
|
|
|
tag: e,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-03-21 23:18:07 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2023-02-02 21:37:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|