stack_wallet/lib/widgets/managed_favorite.dart

185 lines
6 KiB
Dart
Raw Normal View History

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-12 20:02:04 +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';
import '../providers/db/main_db_provider.dart';
import '../themes/coin_icon_provider.dart';
import '../themes/stack_colors.dart';
import '../themes/theme_providers.dart';
import '../utilities/amount/amount.dart';
import '../utilities/amount/amount_formatter.dart';
import '../utilities/constants.dart';
import '../utilities/text_styles.dart';
import '../utilities/util.dart';
import '../wallets/crypto_currency/coins/firo.dart';
import '../wallets/isar/providers/wallet_info_provider.dart';
import 'custom_buttons/favorite_toggle.dart';
import 'rounded_white_container.dart';
2022-08-26 08:11:35 +00:00
class ManagedFavorite extends ConsumerStatefulWidget {
const ManagedFavorite({
2024-05-15 21:20:45 +00:00
super.key,
2022-08-26 08:11:35 +00:00
required this.walletId,
2024-05-15 21:20:45 +00:00
});
2022-08-26 08:11:35 +00:00
final String walletId;
@override
ConsumerState<ManagedFavorite> createState() => _ManagedFavoriteCardState();
}
class _ManagedFavoriteCardState extends ConsumerState<ManagedFavorite> {
@override
Widget build(BuildContext context) {
final walletId = widget.walletId;
debugPrint("BUILD: $runtimeType with walletId $walletId");
2022-08-26 08:11:35 +00:00
2022-09-26 20:21:13 +00:00
final isDesktop = Util.isDesktop;
final coin = ref.watch(pWalletCoin(walletId));
Amount total = ref.watch(pWalletBalance(walletId)).total;
2024-05-15 21:20:45 +00:00
if (coin is Firo) {
final balancePrivate =
ref.watch(pWalletBalanceSecondary(walletId)).total +
ref.watch(pWalletBalanceTertiary(walletId)).total;
total += balancePrivate;
}
final isFavourite = ref.watch(pWalletIsFavourite(walletId));
2022-08-26 08:11:35 +00:00
return RoundedWhiteContainer(
2022-09-26 20:21:13 +00:00
padding: EdgeInsets.all(isDesktop ? 0 : 4.0),
2022-08-26 08:11:35 +00:00
child: RawMaterialButton(
2022-09-22 14:45:24 +00:00
onPressed: () {
ref.read(pWalletInfo(walletId)).updateIsFavourite(
!isFavourite,
isar: ref.read(mainDBProvider).isar,
);
2022-08-26 08:11:35 +00:00
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
child: Padding(
2022-09-26 20:21:13 +00:00
padding: isDesktop
? const EdgeInsets.symmetric(
horizontal: 20,
vertical: 12,
)
: const EdgeInsets.all(8),
2022-08-26 08:11:35 +00:00
child: Row(
children: [
Container(
decoration: BoxDecoration(
2024-05-15 21:20:45 +00:00
color: ref.watch(pCoinColor(coin)).withOpacity(0.5),
2022-08-26 08:11:35 +00:00
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
child: Padding(
2022-09-26 20:21:13 +00:00
padding: EdgeInsets.all(isDesktop ? 6 : 4),
2023-05-12 20:02:04 +00:00
child: SvgPicture.file(
File(
ref.watch(coinIconProvider(coin)),
2023-05-12 20:02:04 +00:00
),
2022-08-26 08:11:35 +00:00
width: 20,
height: 20,
),
),
),
const SizedBox(
width: 12,
),
2022-09-26 20:21:13 +00:00
if (isDesktop)
Expanded(
child: Row(
children: [
Expanded(
child: Text(
ref.watch(pWalletName(walletId)),
2022-09-26 20:21:13 +00:00
style: STextStyles.titleBold12(context),
),
),
Expanded(
child: Text(
2023-05-29 21:10:55 +00:00
ref
.watch(
pAmountFormatter(coin),
2023-05-29 21:10:55 +00:00
)
.format(total),
2022-09-26 20:21:13 +00:00
style: STextStyles.itemSubtitle(context),
),
),
Text(
isFavourite
2022-09-26 20:21:13 +00:00
? "Remove from favorites"
: "Add to favorites",
style:
STextStyles.desktopTextExtraSmall(context).copyWith(
color: isFavourite
2022-09-26 20:21:13 +00:00
? Theme.of(context)
.extension<StackColors>()!
.accentColorRed
: Theme.of(context)
.extension<StackColors>()!
.buttonTextBorderless,
),
2024-05-15 21:20:45 +00:00
),
2022-09-26 20:21:13 +00:00
],
),
2022-09-21 23:32:06 +00:00
),
2022-09-26 20:21:13 +00:00
if (!isDesktop)
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
ref.watch(pWalletName(walletId)),
2022-09-26 20:21:13 +00:00
style: STextStyles.titleBold12(context),
),
const SizedBox(
height: 2,
),
Text(
2023-05-29 21:10:55 +00:00
ref
.watch(
pAmountFormatter(coin),
2023-05-29 21:10:55 +00:00
)
.format(total),
2022-09-26 20:21:13 +00:00
style: STextStyles.itemSubtitle(context),
),
],
),
),
if (!isDesktop)
FavoriteToggle(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
initialState: isFavourite,
2022-09-26 20:21:13 +00:00
onChanged: null,
2022-08-26 08:11:35 +00:00
),
],
),
),
),
);
}
}