stack_wallet/lib/pages/receive_view/addresses/address_card.dart

168 lines
5.6 KiB
Dart
Raw Normal View History

2023-02-02 21:37:59 +00:00
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2023-02-03 19:22:21 +00:00
import 'package:isar/isar.dart';
import 'package:stackwallet/db/main_db.dart';
2023-02-02 21:37:59 +00:00
import 'package:stackwallet/models/isar/models/isar_models.dart';
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/pages/receive_view/addresses/address_qr_popup.dart';
import 'package:stackwallet/pages/receive_view/addresses/edit_address_label_view.dart';
import 'package:stackwallet/utilities/clipboard_interface.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/icon_widgets/copy_icon.dart';
import 'package:stackwallet/widgets/icon_widgets/qrcode_icon.dart';
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,
required this.address,
required this.walletId,
required this.coin,
this.clipboard = const ClipboardWrapper(),
}) : super(key: key);
final Address address;
final String walletId;
final Coin coin;
final ClipboardInterface clipboard;
2023-02-03 19:22:21 +00:00
@override
State<AddressCard> createState() => _AddressCardState();
}
class _AddressCardState extends State<AddressCard> {
late Stream<AddressLabel?> stream;
AddressLabel? label;
@override
void initState() {
label = MainDB.instance
.getAddressLabelSync(widget.walletId, widget.address.value);
Id? id = label?.id;
if (id == null) {
label = AddressLabel(
walletId: widget.walletId,
addressString: widget.address.value,
value: "",
);
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-02-03 19:22:21 +00:00
child: StreamBuilder<AddressLabel?>(
stream: stream,
builder: (context, snapshot) {
if (snapshot.hasData) {
label = snapshot.data!;
}
return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
label!.value,
style: STextStyles.itemSubtitle(context),
2023-02-02 21:37:59 +00:00
),
2023-02-03 19:22:21 +00:00
CustomTextButton(
text: "Edit label",
textSize: 14,
onTap: () {
Navigator.of(context).pushNamed(
EditAddressLabelView.routeName,
2023-03-06 19:27:04 +00:00
arguments: label!.id,
2023-02-03 19:22:21 +00:00
);
},
),
],
2023-02-02 21:37:59 +00:00
),
2023-02-03 19:22:21 +00:00
const SizedBox(
height: 8,
2023-02-02 21:37:59 +00:00
),
2023-02-03 19:22:21 +00:00
Row(
children: [
Expanded(
child: SelectableText(
widget.address.value,
style: STextStyles.itemSubtitle12(context),
2023-02-02 21:37:59 +00:00
),
2023-02-03 19:22:21 +00:00
)
],
2023-02-02 21:37:59 +00:00
),
2023-02-03 19:22:21 +00:00
const SizedBox(
height: 10,
),
Row(
children: [
Expanded(
child: SecondaryButton(
label: "Copy address",
icon: CopyIcon(
color: Theme.of(context)
.extension<StackColors>()!
.buttonTextSecondary,
),
onPressed: () async {
await widget.clipboard.setData(
ClipboardData(
text: widget.address.value,
),
);
2023-03-06 19:27:04 +00:00
if (mounted) {
unawaited(
showFloatingFlushBar(
type: FlushBarType.info,
message: "Copied to clipboard",
context: context,
),
);
}
2023-02-03 19:22:21 +00:00
},
),
),
const SizedBox(
width: 12,
),
Expanded(
child: SecondaryButton(
label: "Show QR Code",
icon: QrCodeIcon(
color: Theme.of(context)
.extension<StackColors>()!
.buttonTextSecondary,
),
onPressed: () {
showDialog<void>(
context: context,
builder: (context) => AddressQrPopup(
addressString: widget.address.value,
coin: widget.coin,
clipboard: widget.clipboard,
),
);
},
),
),
],
)
],
);
}),
2023-02-02 21:37:59 +00:00
);
}
}