mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 20:09:23 +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/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_svg/svg.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/notifications/show_flush_bar.dart';
|
||||||
import 'package:stackwallet/pages/buy_view/buy_in_wallet_view.dart';
|
import 'package:stackwallet/pages/buy_view/buy_in_wallet_view.dart';
|
||||||
import 'package:stackwallet/pages/coin_control/coin_control_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/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/events/global/wallet_sync_status_changed_event.dart';
|
||||||
import 'package:stackwallet/services/event_bus/global_event_bus.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/services/mixins/paynym_wallet_interface.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/constants.dart';
|
import 'package:stackwallet/utilities/constants.dart';
|
||||||
|
@ -255,19 +258,14 @@ class _WalletViewState extends ConsumerState<WalletView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onExchangePressed(BuildContext context) async {
|
void _onExchangePressed(BuildContext context) async {
|
||||||
// too expensive
|
|
||||||
// unawaited(ExchangeDataLoadingService.instance.loadAll(ref));
|
|
||||||
|
|
||||||
final coin = ref.read(managerProvider).coin;
|
final coin = ref.read(managerProvider).coin;
|
||||||
|
|
||||||
if (coin == Coin.epicCash) {
|
final currency = ExchangeDataLoadingService.instance.isar.currencies
|
||||||
await showDialog<void>(
|
.where()
|
||||||
context: context,
|
.tickerEqualToAnyExchangeNameName(coin.ticker)
|
||||||
builder: (_) => const StackOkDialog(
|
.findFirstSync();
|
||||||
title: "Exchange not available for Epic Cash",
|
|
||||||
),
|
if (coin.isTestNet) {
|
||||||
);
|
|
||||||
} else if (coin.name.endsWith("TestNet")) {
|
|
||||||
await showDialog<void>(
|
await showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => const StackOkDialog(
|
builder: (_) => const StackOkDialog(
|
||||||
|
@ -275,41 +273,13 @@ class _WalletViewState extends ConsumerState<WalletView> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} 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) {
|
if (mounted) {
|
||||||
unawaited(
|
unawaited(
|
||||||
Navigator.of(context).pushNamed(
|
Navigator.of(context).pushNamed(
|
||||||
WalletInitiatedExchangeView.routeName,
|
WalletInitiatedExchangeView.routeName,
|
||||||
arguments: Tuple2(
|
arguments: Tuple2(
|
||||||
walletId,
|
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 {
|
Future<void> attemptAnonymize() async {
|
||||||
bool shouldPop = false;
|
bool shouldPop = false;
|
||||||
unawaited(
|
unawaited(
|
||||||
|
@ -818,23 +810,20 @@ class _WalletViewState extends ConsumerState<WalletView> {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
WalletNavigationBarItemData(
|
if (Constants.enableExchange)
|
||||||
label: "Exchange",
|
WalletNavigationBarItemData(
|
||||||
icon: const ExchangeNavIcon(),
|
label: "Swap",
|
||||||
onTap: () => _onExchangePressed(context),
|
icon: const ExchangeNavIcon(),
|
||||||
),
|
onTap: () => _onExchangePressed(context),
|
||||||
WalletNavigationBarItemData(
|
),
|
||||||
label: "Buy",
|
if (Constants.enableExchange)
|
||||||
icon: const BuyNavIcon(),
|
WalletNavigationBarItemData(
|
||||||
onTap: () {
|
label: "Buy",
|
||||||
unawaited(
|
icon: const BuyNavIcon(),
|
||||||
Navigator.of(context).pushNamed(
|
onTap: () => _onBuyPressed(context),
|
||||||
BuyInWalletView.routeName,
|
),
|
||||||
arguments: coin,
|
],
|
||||||
),
|
moreItems: [
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (ref.watch(
|
if (ref.watch(
|
||||||
walletsChangeNotifierProvider.select(
|
walletsChangeNotifierProvider.select(
|
||||||
(value) => value
|
(value) => value
|
||||||
|
|
|
@ -4,19 +4,20 @@ import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
import 'package:stackwallet/utilities/theme/stack_colors.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';
|
import 'package:stackwallet/widgets/wallet_navigation_bar/components/wallet_navigation_bar_item.dart';
|
||||||
|
|
||||||
const _kMaxItems = 5;
|
|
||||||
|
|
||||||
final walletNavBarMore = StateProvider.autoDispose((ref) => false);
|
final walletNavBarMore = StateProvider.autoDispose((ref) => false);
|
||||||
|
|
||||||
class WalletNavigationBar extends ConsumerStatefulWidget {
|
class WalletNavigationBar extends ConsumerStatefulWidget {
|
||||||
const WalletNavigationBar({
|
const WalletNavigationBar({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.items,
|
required this.items,
|
||||||
|
required this.moreItems,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final List<WalletNavigationBarItemData> items;
|
final List<WalletNavigationBarItemData> items;
|
||||||
|
final List<WalletNavigationBarItemData> moreItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ConsumerState<WalletNavigationBar> createState() =>
|
ConsumerState<WalletNavigationBar> createState() =>
|
||||||
|
@ -28,23 +29,18 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
||||||
|
|
||||||
final _moreDuration = const Duration(milliseconds: 200);
|
final _moreDuration = const Duration(milliseconds: 200);
|
||||||
|
|
||||||
late final bool hasMore;
|
|
||||||
|
|
||||||
double _moreScale = 0;
|
|
||||||
|
|
||||||
void _onMorePressed() {
|
void _onMorePressed() {
|
||||||
ref.read(walletNavBarMore.state).state =
|
ref.read(walletNavBarMore.state).state =
|
||||||
!ref.read(walletNavBarMore.state).state;
|
!ref.read(walletNavBarMore.state).state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
hasMore = widget.items.length > _kMaxItems;
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return Stack(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
children: [
|
children: [
|
||||||
|
@ -93,7 +89,7 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
...widget.items.sublist(_kMaxItems - 1).map(
|
...widget.moreItems.map(
|
||||||
(e) {
|
(e) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
|
@ -133,94 +129,92 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
vertical: 6,
|
vertical: 6,
|
||||||
horizontal: 12,
|
horizontal: 20,
|
||||||
),
|
),
|
||||||
child: IntrinsicWidth(
|
// child: IntrinsicWidth(
|
||||||
child: Row(
|
child: ConditionalParent(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
condition: buttonCount > 4,
|
||||||
children: [
|
builder: (child) => SizedBox(
|
||||||
const Spacer(),
|
width: width * 0.9,
|
||||||
if (!hasMore)
|
child: child,
|
||||||
|
),
|
||||||
|
child: ConditionalParent(
|
||||||
|
condition: buttonCount <= 4,
|
||||||
|
builder: (child) => SizedBox(
|
||||||
|
width: width * 0.2 * buttonCount,
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
...widget.items.map(
|
...widget.items.map(
|
||||||
(e) => Flexible(
|
(e) => Expanded(
|
||||||
flex: 10000,
|
|
||||||
child: WalletNavigationBarItem(
|
child: WalletNavigationBarItem(
|
||||||
data: e,
|
data: e,
|
||||||
disableDuration: _moreDuration,
|
disableDuration: _moreDuration,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (hasMore)
|
if (hasMore)
|
||||||
...widget.items.sublist(0, _kMaxItems - 1).map(
|
Expanded(
|
||||||
(e) => Flexible(
|
child: WalletNavigationBarItem(
|
||||||
flex: 10000,
|
data: WalletNavigationBarItemData(
|
||||||
child: WalletNavigationBarItem(
|
icon: AnimatedCrossFade(
|
||||||
data: e,
|
firstChild: SvgPicture.asset(
|
||||||
disableDuration: _moreDuration,
|
Assets.svg.bars,
|
||||||
),
|
width: 20,
|
||||||
),
|
height: 20,
|
||||||
),
|
color: Theme.of(context)
|
||||||
if (hasMore)
|
.extension<StackColors>()!
|
||||||
Flexible(
|
.bottomNavIconIcon,
|
||||||
flex: 10000,
|
),
|
||||||
child: WalletNavigationBarItem(
|
secondChild: SvgPicture.asset(
|
||||||
data: WalletNavigationBarItemData(
|
Assets.svg.bars,
|
||||||
icon: AnimatedCrossFade(
|
width: 20,
|
||||||
firstChild: SvgPicture.asset(
|
height: 20,
|
||||||
Assets.svg.bars,
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.bottomNavIconIcon,
|
|
||||||
),
|
|
||||||
secondChild: SvgPicture.asset(
|
|
||||||
Assets.svg.bars,
|
|
||||||
width: 20,
|
|
||||||
height: 20,
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.infoItemIcons,
|
|
||||||
),
|
|
||||||
crossFadeState: ref
|
|
||||||
.watch(walletNavBarMore.state)
|
|
||||||
.state
|
|
||||||
? CrossFadeState.showSecond
|
|
||||||
: CrossFadeState.showFirst,
|
|
||||||
duration: _moreDuration,
|
|
||||||
),
|
|
||||||
overrideText: AnimatedCrossFade(
|
|
||||||
firstChild: Text(
|
|
||||||
"More",
|
|
||||||
style:
|
|
||||||
STextStyles.buttonSmall(context),
|
|
||||||
),
|
|
||||||
secondChild: Text(
|
|
||||||
"More",
|
|
||||||
style:
|
|
||||||
STextStyles.buttonSmall(context)
|
|
||||||
.copyWith(
|
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<StackColors>()!
|
.extension<StackColors>()!
|
||||||
.infoItemIcons,
|
.infoItemIcons,
|
||||||
),
|
),
|
||||||
|
crossFadeState: ref
|
||||||
|
.watch(walletNavBarMore.state)
|
||||||
|
.state
|
||||||
|
? CrossFadeState.showSecond
|
||||||
|
: CrossFadeState.showFirst,
|
||||||
|
duration: _moreDuration,
|
||||||
),
|
),
|
||||||
crossFadeState: ref
|
overrideText: AnimatedCrossFade(
|
||||||
.watch(walletNavBarMore.state)
|
firstChild: Text(
|
||||||
.state
|
"More",
|
||||||
? CrossFadeState.showSecond
|
style: STextStyles.buttonSmall(
|
||||||
: CrossFadeState.showFirst,
|
context),
|
||||||
duration: _moreDuration,
|
),
|
||||||
|
secondChild: Text(
|
||||||
|
"More",
|
||||||
|
style:
|
||||||
|
STextStyles.buttonSmall(context)
|
||||||
|
.copyWith(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.infoItemIcons,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
crossFadeState: ref
|
||||||
|
.watch(walletNavBarMore.state)
|
||||||
|
.state
|
||||||
|
? CrossFadeState.showSecond
|
||||||
|
: CrossFadeState.showFirst,
|
||||||
|
duration: _moreDuration,
|
||||||
|
),
|
||||||
|
label: null,
|
||||||
|
isMore: true,
|
||||||
|
onTap: _onMorePressed,
|
||||||
),
|
),
|
||||||
label: null,
|
disableDuration: _moreDuration,
|
||||||
isMore: true,
|
|
||||||
onTap: _onMorePressed,
|
|
||||||
),
|
),
|
||||||
disableDuration: _moreDuration,
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
const Spacer(),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue