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 'package:stackwallet/providers/providers.dart';
|
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
|
|
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
|
|
|
import 'package:stackwallet/utilities/format.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-09-22 23:48:50 +00:00
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2022-09-26 20:21:13 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
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}");
|
|
|
|
|
2022-09-26 20:21:13 +00:00
|
|
|
final isDesktop = Util.isDesktop;
|
|
|
|
|
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: () {
|
2022-08-26 08:11:35 +00:00
|
|
|
final provider = ref
|
|
|
|
.read(walletsChangeNotifierProvider)
|
|
|
|
.getManagerProvider(manager.walletId);
|
|
|
|
if (!manager.isFavorite) {
|
|
|
|
ref.read(favoritesProvider).add(provider, true);
|
|
|
|
ref.read(nonFavoritesProvider).remove(provider, true);
|
2022-09-22 14:45:24 +00:00
|
|
|
ref
|
2022-08-26 08:11:35 +00:00
|
|
|
.read(walletsServiceChangeNotifierProvider)
|
|
|
|
.addFavorite(manager.walletId);
|
|
|
|
} else {
|
|
|
|
ref.read(favoritesProvider).remove(provider, true);
|
|
|
|
ref.read(nonFavoritesProvider).add(provider, true);
|
2022-09-22 14:45:24 +00:00
|
|
|
ref
|
2022-08-26 08:11:35 +00:00
|
|
|
.read(walletsServiceChangeNotifierProvider)
|
|
|
|
.removeFavorite(manager.walletId);
|
|
|
|
}
|
|
|
|
|
|
|
|
manager.isFavorite = !manager.isFavorite;
|
|
|
|
},
|
|
|
|
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(
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-09-21 21:59:52 +00:00
|
|
|
.colorForCoin(manager.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),
|
2022-08-26 08:11:35 +00:00
|
|
|
child: SvgPicture.asset(
|
|
|
|
Assets.svg.iconFor(coin: manager.coin),
|
|
|
|
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(
|
|
|
|
manager.walletName,
|
|
|
|
style: STextStyles.titleBold12(context),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
"${Format.localizedStringAsFixed(
|
|
|
|
value: manager.cachedTotalBalance,
|
|
|
|
locale: ref.watch(
|
|
|
|
localeServiceChangeNotifierProvider
|
|
|
|
.select((value) => value.locale)),
|
|
|
|
decimalPlaces: 8,
|
|
|
|
)} ${manager.coin.ticker}",
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
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(
|
|
|
|
manager.walletName,
|
|
|
|
style: STextStyles.titleBold12(context),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"${Format.localizedStringAsFixed(
|
|
|
|
value: manager.cachedTotalBalance,
|
|
|
|
locale: ref.watch(localeServiceChangeNotifierProvider
|
|
|
|
.select((value) => value.locale)),
|
|
|
|
decimalPlaces: 8,
|
|
|
|
)} ${manager.coin.ticker}",
|
|
|
|
style: STextStyles.itemSubtitle(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (!isDesktop)
|
|
|
|
FavoriteToggle(
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
Constants.size.circularBorderRadius,
|
|
|
|
),
|
|
|
|
initialState: manager.isFavorite,
|
|
|
|
onChanged: null,
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|