2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-05-14 03:24:42 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:flutter_svg/svg.dart';
|
2023-05-15 20:12:06 +00:00
|
|
|
import 'package:stackwallet/models/isar/models/contact_entry.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/pages/address_book_views/subviews/contact_popup.dart';
|
|
|
|
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2023-05-14 03:24:42 +00:00
|
|
|
import 'package:stackwallet/themes/theme_providers.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-11-01 21:58:41 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2022-11-17 16:12:59 +00:00
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
|
|
|
import 'package:stackwallet/widgets/expandable.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
|
|
|
|
|
|
|
class AddressBookCard extends ConsumerStatefulWidget {
|
2022-11-02 16:01:03 +00:00
|
|
|
const AddressBookCard({
|
|
|
|
Key? key,
|
|
|
|
required this.contactId,
|
|
|
|
this.indicatorDown,
|
2022-11-17 17:10:26 +00:00
|
|
|
this.desktopSendFrom = true,
|
2022-11-02 16:01:03 +00:00
|
|
|
}) : super(key: key);
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
final String contactId;
|
2022-11-17 16:12:59 +00:00
|
|
|
final ExpandableState? indicatorDown;
|
2022-11-17 17:10:26 +00:00
|
|
|
final bool desktopSendFrom;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
ConsumerState<AddressBookCard> createState() => _AddressBookCardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AddressBookCardState extends ConsumerState<AddressBookCard> {
|
|
|
|
late final String contactId;
|
2022-11-01 21:58:41 +00:00
|
|
|
late final bool isDesktop;
|
2022-11-17 17:10:26 +00:00
|
|
|
late final bool desktopSendFrom;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
contactId = widget.contactId;
|
2022-11-17 17:10:26 +00:00
|
|
|
desktopSendFrom = widget.desktopSendFrom;
|
2022-11-01 21:58:41 +00:00
|
|
|
isDesktop = Util.isDesktop;
|
2022-08-26 08:11:35 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-18 15:07:31 +00:00
|
|
|
// provider hack to prevent trying to update widget with deleted contact
|
2023-05-15 20:12:06 +00:00
|
|
|
ContactEntry? _contact;
|
2022-11-18 15:07:31 +00:00
|
|
|
try {
|
|
|
|
_contact = ref.watch(addressBookServiceProvider
|
|
|
|
.select((value) => value.getContactById(contactId)));
|
|
|
|
} catch (_) {
|
|
|
|
return Container();
|
|
|
|
}
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-11-18 15:07:31 +00:00
|
|
|
final contact = _contact!;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
final List<Coin> coins = [];
|
2023-07-04 23:40:06 +00:00
|
|
|
|
|
|
|
for (final coin in Coin.values) {
|
|
|
|
if (contact.addresses.where((e) => e.coin == coin).isNotEmpty) {
|
|
|
|
coins.add(coin);
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String coinsString = "";
|
|
|
|
if (coins.isNotEmpty) {
|
|
|
|
coinsString = coins[0].ticker;
|
|
|
|
for (int i = 1; i < coins.length; i++) {
|
|
|
|
coinsString += ", ${coins[i].ticker}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:12:59 +00:00
|
|
|
return ConditionalParent(
|
|
|
|
condition: !isDesktop,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 32,
|
|
|
|
height: 32,
|
|
|
|
decoration: BoxDecoration(
|
2023-05-15 20:12:06 +00:00
|
|
|
color: contact.customId == "default"
|
2022-11-17 16:12:59 +00:00
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.myStackContactIconBG
|
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textFieldDefaultBG,
|
|
|
|
borderRadius: BorderRadius.circular(32),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
2023-05-15 20:12:06 +00:00
|
|
|
child: contact.customId == "default"
|
2022-11-17 16:12:59 +00:00
|
|
|
? Center(
|
2023-05-14 03:24:42 +00:00
|
|
|
child: SvgPicture.file(
|
|
|
|
File(
|
|
|
|
ref.watch(
|
|
|
|
themeProvider.select(
|
|
|
|
(value) => value.assets.stackIcon,
|
|
|
|
),
|
2023-04-25 22:07:28 +00:00
|
|
|
),
|
|
|
|
),
|
2022-11-17 16:12:59 +00:00
|
|
|
width: 20,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: contact.emojiChar != null
|
2022-08-26 08:11:35 +00:00
|
|
|
? Center(
|
2022-11-17 16:12:59 +00:00
|
|
|
child: Text(contact.emojiChar!),
|
|
|
|
)
|
|
|
|
: Center(
|
2022-08-26 08:11:35 +00:00
|
|
|
child: SvgPicture.asset(
|
2022-11-17 16:12:59 +00:00
|
|
|
Assets.svg.user,
|
|
|
|
width: 18,
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
2022-11-17 16:12:59 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 12,
|
|
|
|
),
|
|
|
|
if (isDesktop)
|
|
|
|
Text(
|
|
|
|
contact.name,
|
|
|
|
style: STextStyles.itemSubtitle12(context),
|
|
|
|
),
|
|
|
|
if (isDesktop)
|
|
|
|
const SizedBox(
|
|
|
|
width: 16,
|
|
|
|
),
|
2023-06-08 18:16:47 +00:00
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: isDesktop && !desktopSendFrom
|
|
|
|
? CrossAxisAlignment.end
|
|
|
|
: CrossAxisAlignment.start,
|
2022-11-17 16:12:59 +00:00
|
|
|
children: [
|
2023-06-08 18:16:47 +00:00
|
|
|
if (!isDesktop)
|
|
|
|
Text(
|
|
|
|
contact.name,
|
|
|
|
style: STextStyles.itemSubtitle12(context),
|
|
|
|
),
|
|
|
|
if (!isDesktop)
|
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
2022-11-01 21:58:41 +00:00
|
|
|
Text(
|
|
|
|
coinsString,
|
|
|
|
style: STextStyles.label(context),
|
2023-06-08 18:16:47 +00:00
|
|
|
textAlign: isDesktop && !desktopSendFrom
|
|
|
|
? TextAlign.right
|
|
|
|
: TextAlign.left,
|
2022-11-01 21:58:41 +00:00
|
|
|
),
|
2022-11-17 16:12:59 +00:00
|
|
|
],
|
|
|
|
),
|
2023-06-08 18:16:47 +00:00
|
|
|
),
|
2022-11-17 17:10:26 +00:00
|
|
|
if (isDesktop && desktopSendFrom) const Spacer(),
|
|
|
|
if (isDesktop && desktopSendFrom)
|
2022-11-17 16:12:59 +00:00
|
|
|
SvgPicture.asset(
|
|
|
|
widget.indicatorDown == ExpandableState.collapsed
|
|
|
|
? Assets.svg.chevronDown
|
|
|
|
: Assets.svg.chevronUp,
|
|
|
|
width: 10,
|
|
|
|
height: 5,
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.textSubtitle2,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
builder: (child) => RoundedWhiteContainer(
|
|
|
|
padding: const EdgeInsets.all(4),
|
|
|
|
child: RawMaterialButton(
|
|
|
|
// splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
|
|
|
padding: const EdgeInsets.all(0),
|
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
Constants.size.circularBorderRadius,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
showDialog<void>(
|
|
|
|
context: context,
|
|
|
|
useSafeArea: true,
|
|
|
|
barrierDismissible: true,
|
|
|
|
builder: (_) => ContactPopUp(
|
2023-05-15 20:12:06 +00:00
|
|
|
contactId: contact.customId,
|
2022-11-17 16:12:59 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: child,
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|