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/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> {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
if (Constants.enableExchange)
|
||||||
WalletNavigationBarItemData(
|
WalletNavigationBarItemData(
|
||||||
label: "Exchange",
|
label: "Swap",
|
||||||
icon: const ExchangeNavIcon(),
|
icon: const ExchangeNavIcon(),
|
||||||
onTap: () => _onExchangePressed(context),
|
onTap: () => _onExchangePressed(context),
|
||||||
),
|
),
|
||||||
|
if (Constants.enableExchange)
|
||||||
WalletNavigationBarItemData(
|
WalletNavigationBarItemData(
|
||||||
label: "Buy",
|
label: "Buy",
|
||||||
icon: const BuyNavIcon(),
|
icon: const BuyNavIcon(),
|
||||||
onTap: () {
|
onTap: () => _onBuyPressed(context),
|
||||||
unawaited(
|
|
||||||
Navigator.of(context).pushNamed(
|
|
||||||
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,17 +129,26 @@ 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: 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(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
const Spacer(),
|
|
||||||
if (!hasMore)
|
|
||||||
...widget.items.map(
|
...widget.items.map(
|
||||||
(e) => Flexible(
|
(e) => Expanded(
|
||||||
flex: 10000,
|
|
||||||
child: WalletNavigationBarItem(
|
child: WalletNavigationBarItem(
|
||||||
data: e,
|
data: e,
|
||||||
disableDuration: _moreDuration,
|
disableDuration: _moreDuration,
|
||||||
|
@ -151,18 +156,7 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (hasMore)
|
if (hasMore)
|
||||||
...widget.items.sublist(0, _kMaxItems - 1).map(
|
Expanded(
|
||||||
(e) => Flexible(
|
|
||||||
flex: 10000,
|
|
||||||
child: WalletNavigationBarItem(
|
|
||||||
data: e,
|
|
||||||
disableDuration: _moreDuration,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (hasMore)
|
|
||||||
Flexible(
|
|
||||||
flex: 10000,
|
|
||||||
child: WalletNavigationBarItem(
|
child: WalletNavigationBarItem(
|
||||||
data: WalletNavigationBarItemData(
|
data: WalletNavigationBarItemData(
|
||||||
icon: AnimatedCrossFade(
|
icon: AnimatedCrossFade(
|
||||||
|
@ -192,8 +186,8 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
||||||
overrideText: AnimatedCrossFade(
|
overrideText: AnimatedCrossFade(
|
||||||
firstChild: Text(
|
firstChild: Text(
|
||||||
"More",
|
"More",
|
||||||
style:
|
style: STextStyles.buttonSmall(
|
||||||
STextStyles.buttonSmall(context),
|
context),
|
||||||
),
|
),
|
||||||
secondChild: Text(
|
secondChild: Text(
|
||||||
"More",
|
"More",
|
||||||
|
@ -219,13 +213,13 @@ class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
|
||||||
disableDuration: _moreDuration,
|
disableDuration: _moreDuration,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Spacer(),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue