mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
wallet nav bar tweaks
This commit is contained in:
parent
a5a2dcef64
commit
da791d483b
2 changed files with 125 additions and 142 deletions
|
@ -5,6 +5,8 @@ import 'package:event_bus/event_bus.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/models/isar/exchange_cache/currency.dart';
|
||||
import 'package:stackwallet/notifications/show_flush_bar.dart';
|
||||
import 'package:stackwallet/pages/buy_view/buy_in_wallet_view.dart';
|
||||
import 'package:stackwallet/pages/coin_control/coin_control_view.dart';
|
||||
|
@ -33,6 +35,7 @@ import 'package:stackwallet/services/coins/manager.dart';
|
|||
import 'package:stackwallet/services/event_bus/events/global/node_connection_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||
import 'package:stackwallet/services/event_bus/global_event_bus.dart';
|
||||
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
|
||||
import 'package:stackwallet/services/mixins/paynym_wallet_interface.dart';
|
||||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
|
@ -255,19 +258,14 @@ class _WalletViewState extends ConsumerState<WalletView> {
|
|||
}
|
||||
|
||||
void _onExchangePressed(BuildContext context) async {
|
||||
// too expensive
|
||||
// unawaited(ExchangeDataLoadingService.instance.loadAll(ref));
|
||||
|
||||
final coin = ref.read(managerProvider).coin;
|
||||
|
||||
if (coin == Coin.epicCash) {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => const StackOkDialog(
|
||||
title: "Exchange not available for Epic Cash",
|
||||
),
|
||||
);
|
||||
} else if (coin.name.endsWith("TestNet")) {
|
||||
final currency = ExchangeDataLoadingService.instance.isar.currencies
|
||||
.where()
|
||||
.tickerEqualToAnyExchangeNameName(coin.ticker)
|
||||
.findFirstSync();
|
||||
|
||||
if (coin.isTestNet) {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => const StackOkDialog(
|
||||
|
@ -275,41 +273,13 @@ class _WalletViewState extends ConsumerState<WalletView> {
|
|||
),
|
||||
);
|
||||
} else {
|
||||
// ref.read(currentExchangeNameStateProvider.state).state =
|
||||
// ChangeNowExchange.exchangeName;
|
||||
// final walletId = ref.read(managerProvider).walletId;
|
||||
// ref.read(prefsChangeNotifierProvider).exchangeRateType =
|
||||
// ExchangeRateType.estimated;
|
||||
//
|
||||
// final currencies = ref
|
||||
// .read(availableChangeNowCurrenciesProvider)
|
||||
// .currencies
|
||||
// .where((element) =>
|
||||
// element.ticker.toLowerCase() == coin.ticker.toLowerCase());
|
||||
//
|
||||
// if (currencies.isNotEmpty) {
|
||||
// ref
|
||||
// .read(exchangeFormStateProvider(ExchangeRateType.estimated))
|
||||
// .setCurrencies(
|
||||
// currencies.first,
|
||||
// ref
|
||||
// .read(availableChangeNowCurrenciesProvider)
|
||||
// .currencies
|
||||
// .firstWhere(
|
||||
// (element) =>
|
||||
// element.ticker.toLowerCase() !=
|
||||
// coin.ticker.toLowerCase(),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
|
||||
if (mounted) {
|
||||
unawaited(
|
||||
Navigator.of(context).pushNamed(
|
||||
WalletInitiatedExchangeView.routeName,
|
||||
arguments: Tuple2(
|
||||
walletId,
|
||||
coin,
|
||||
currency == null ? Coin.bitcoin : coin,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -317,6 +287,28 @@ class _WalletViewState extends ConsumerState<WalletView> {
|
|||
}
|
||||
}
|
||||
|
||||
void _onBuyPressed(BuildContext context) async {
|
||||
final coin = ref.read(managerProvider).coin;
|
||||
|
||||
if (coin.isTestNet) {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => const StackOkDialog(
|
||||
title: "Buy not available for test net coins",
|
||||
),
|
||||
);
|
||||
} else {
|
||||
if (mounted) {
|
||||
unawaited(
|
||||
Navigator.of(context).pushNamed(
|
||||
BuyInWalletView.routeName,
|
||||
arguments: coin.hasBuySupport ? coin : Coin.bitcoin,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> attemptAnonymize() async {
|
||||
bool shouldPop = false;
|
||||
unawaited(
|
||||
|
@ -818,23 +810,20 @@ class _WalletViewState extends ConsumerState<WalletView> {
|
|||
);
|
||||
},
|
||||
),
|
||||
if (Constants.enableExchange)
|
||||
WalletNavigationBarItemData(
|
||||
label: "Exchange",
|
||||
label: "Swap",
|
||||
icon: const ExchangeNavIcon(),
|
||||
onTap: () => _onExchangePressed(context),
|
||||
),
|
||||
if (Constants.enableExchange)
|
||||
WalletNavigationBarItemData(
|
||||
label: "Buy",
|
||||
icon: const BuyNavIcon(),
|
||||
onTap: () {
|
||||
unawaited(
|
||||
Navigator.of(context).pushNamed(
|
||||
BuyInWalletView.routeName,
|
||||
arguments: coin,
|
||||
),
|
||||
);
|
||||
},
|
||||
onTap: () => _onBuyPressed(context),
|
||||
),
|
||||
],
|
||||
moreItems: [
|
||||
if (ref.watch(
|
||||
walletsChangeNotifierProvider.select(
|
||||
(value) => value
|
||||
|
|
|
@ -4,19 +4,20 @@ import 'package:flutter_svg/svg.dart';
|
|||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||
import 'package:stackwallet/widgets/conditional_parent.dart';
|
||||
import 'package:stackwallet/widgets/wallet_navigation_bar/components/wallet_navigation_bar_item.dart';
|
||||
|
||||
const _kMaxItems = 5;
|
||||
|
||||
final walletNavBarMore = StateProvider.autoDispose((ref) => false);
|
||||
|
||||
class WalletNavigationBar extends ConsumerStatefulWidget {
|
||||
const WalletNavigationBar({
|
||||
Key? key,
|
||||
required this.items,
|
||||
required this.moreItems,
|
||||
}) : super(key: key);
|
||||
|
||||
final List<WalletNavigationBarItemData> items;
|
||||
final List<WalletNavigationBarItemData> moreItems;
|
||||
|
||||
@override
|
||||
ConsumerState<WalletNavigationBar> createState() =>
|
||||
|
@ -28,23 +29,18 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
|||
|
||||
final _moreDuration = const Duration(milliseconds: 200);
|
||||
|
||||
late final bool hasMore;
|
||||
|
||||
double _moreScale = 0;
|
||||
|
||||
void _onMorePressed() {
|
||||
ref.read(walletNavBarMore.state).state =
|
||||
!ref.read(walletNavBarMore.state).state;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
hasMore = widget.items.length > _kMaxItems;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final width = MediaQuery.of(context).size.width - 40;
|
||||
|
||||
final hasMore = widget.moreItems.isNotEmpty;
|
||||
final buttonCount = widget.items.length + (hasMore ? 1 : 0);
|
||||
|
||||
return Stack(
|
||||
alignment: Alignment.bottomCenter,
|
||||
children: [
|
||||
|
@ -93,7 +89,7 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
|||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
...widget.items.sublist(_kMaxItems - 1).map(
|
||||
...widget.moreItems.map(
|
||||
(e) {
|
||||
return Column(
|
||||
children: [
|
||||
|
@ -133,17 +129,26 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
|||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 6,
|
||||
horizontal: 12,
|
||||
horizontal: 20,
|
||||
),
|
||||
// child: IntrinsicWidth(
|
||||
child: ConditionalParent(
|
||||
condition: buttonCount > 4,
|
||||
builder: (child) => SizedBox(
|
||||
width: width * 0.9,
|
||||
child: child,
|
||||
),
|
||||
child: ConditionalParent(
|
||||
condition: buttonCount <= 4,
|
||||
builder: (child) => SizedBox(
|
||||
width: width * 0.2 * buttonCount,
|
||||
child: child,
|
||||
),
|
||||
child: IntrinsicWidth(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Spacer(),
|
||||
if (!hasMore)
|
||||
...widget.items.map(
|
||||
(e) => Flexible(
|
||||
flex: 10000,
|
||||
(e) => Expanded(
|
||||
child: WalletNavigationBarItem(
|
||||
data: e,
|
||||
disableDuration: _moreDuration,
|
||||
|
@ -151,18 +156,7 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
|||
),
|
||||
),
|
||||
if (hasMore)
|
||||
...widget.items.sublist(0, _kMaxItems - 1).map(
|
||||
(e) => Flexible(
|
||||
flex: 10000,
|
||||
child: WalletNavigationBarItem(
|
||||
data: e,
|
||||
disableDuration: _moreDuration,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (hasMore)
|
||||
Flexible(
|
||||
flex: 10000,
|
||||
Expanded(
|
||||
child: WalletNavigationBarItem(
|
||||
data: WalletNavigationBarItemData(
|
||||
icon: AnimatedCrossFade(
|
||||
|
@ -192,8 +186,8 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
|||
overrideText: AnimatedCrossFade(
|
||||
firstChild: Text(
|
||||
"More",
|
||||
style:
|
||||
STextStyles.buttonSmall(context),
|
||||
style: STextStyles.buttonSmall(
|
||||
context),
|
||||
),
|
||||
secondChild: Text(
|
||||
"More",
|
||||
|
@ -219,13 +213,13 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
|||
disableDuration: _moreDuration,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue