stack_wallet/lib/widgets/managed_favorite.dart
julian 1449814e35 Merge branch 'amount_display_precision' into add_nano
# Conflicts:
#	lib/pages/pinpad_views/create_pin_view.dart
#	lib/widgets/custom_pin_put/custom_pin_put_state.dart
2023-05-30 09:11:41 -06:00

209 lines
7.2 KiB
Dart

/*
* 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
*
*/
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/services/coins/firo/firo_wallet.dart';
import 'package:stackwallet/themes/coin_icon_provider.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/amount/amount.dart';
import 'package:stackwallet/utilities/amount/amount_formatter.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/widgets/custom_buttons/favorite_toggle.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
class ManagedFavorite extends ConsumerStatefulWidget {
const ManagedFavorite({
Key? key,
required this.walletId,
}) : super(key: key);
final String walletId;
@override
ConsumerState<ManagedFavorite> createState() => _ManagedFavoriteCardState();
}
class _ManagedFavoriteCardState extends ConsumerState<ManagedFavorite> {
@override
Widget build(BuildContext context) {
final manager = ref.watch(walletsChangeNotifierProvider
.select((value) => value.getManager(widget.walletId)));
debugPrint("BUILD: $runtimeType with walletId ${widget.walletId}");
final isDesktop = Util.isDesktop;
final balance = ref.watch(
walletsChangeNotifierProvider.select(
(value) => value.getManager(widget.walletId).balance,
),
);
Amount total = balance.total;
if (manager.coin == Coin.firo || manager.coin == Coin.firoTestNet) {
final balancePrivate = ref.watch(
walletsChangeNotifierProvider.select(
(value) => (value
.getManager(
widget.walletId,
)
.wallet as FiroWallet)
.balancePrivate,
),
);
total += balancePrivate.total;
}
return RoundedWhiteContainer(
padding: EdgeInsets.all(isDesktop ? 0 : 4.0),
child: RawMaterialButton(
onPressed: () {
final provider = ref
.read(walletsChangeNotifierProvider)
.getManagerProvider(manager.walletId);
if (!manager.isFavorite) {
ref.read(favoritesProvider).add(provider, true);
ref.read(nonFavoritesProvider).remove(provider, true);
ref
.read(walletsServiceChangeNotifierProvider)
.addFavorite(manager.walletId);
} else {
ref.read(favoritesProvider).remove(provider, true);
ref.read(nonFavoritesProvider).add(provider, true);
ref
.read(walletsServiceChangeNotifierProvider)
.removeFavorite(manager.walletId);
}
manager.isFavorite = !manager.isFavorite;
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
child: Padding(
padding: isDesktop
? const EdgeInsets.symmetric(
horizontal: 20,
vertical: 12,
)
: const EdgeInsets.all(8),
child: Row(
children: [
Container(
decoration: BoxDecoration(
color: Theme.of(context)
.extension<StackColors>()!
.colorForCoin(manager.coin)
.withOpacity(0.5),
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
child: Padding(
padding: EdgeInsets.all(isDesktop ? 6 : 4),
child: SvgPicture.file(
File(
ref.watch(coinIconProvider(manager.coin)),
),
width: 20,
height: 20,
),
),
),
const SizedBox(
width: 12,
),
if (isDesktop)
Expanded(
child: Row(
children: [
Expanded(
child: Text(
manager.walletName,
style: STextStyles.titleBold12(context),
),
),
Expanded(
child: Text(
ref
.watch(
pAmountFormatter(manager.coin),
)
.format(total),
style: STextStyles.itemSubtitle(context),
),
),
Text(
manager.isFavorite
? "Remove from favorites"
: "Add to favorites",
style:
STextStyles.desktopTextExtraSmall(context).copyWith(
color: manager.isFavorite
? Theme.of(context)
.extension<StackColors>()!
.accentColorRed
: Theme.of(context)
.extension<StackColors>()!
.buttonTextBorderless,
),
)
],
),
),
if (!isDesktop)
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
manager.walletName,
style: STextStyles.titleBold12(context),
),
const SizedBox(
height: 2,
),
Text(
ref
.watch(
pAmountFormatter(manager.coin),
)
.format(total),
style: STextStyles.itemSubtitle(context),
),
],
),
),
if (!isDesktop)
FavoriteToggle(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
initialState: manager.isFavorite,
onChanged: null,
),
],
),
),
),
);
}
}