stack_wallet/lib/widgets/wallet_navigation_bar/wallet_navigation_bar.dart

233 lines
9.8 KiB
Dart
Raw Normal View History

2023-03-10 18:42:45 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
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';
2023-03-10 22:48:44 +00:00
import 'package:stackwallet/widgets/conditional_parent.dart';
2023-03-10 18:42:45 +00:00
import 'package:stackwallet/widgets/wallet_navigation_bar/components/wallet_navigation_bar_item.dart';
final walletNavBarMore = StateProvider.autoDispose((ref) => false);
class WalletNavigationBar extends ConsumerStatefulWidget {
const WalletNavigationBar({
Key? key,
required this.items,
2023-03-10 22:48:44 +00:00
required this.moreItems,
2023-03-10 18:42:45 +00:00
}) : super(key: key);
final List<WalletNavigationBarItemData> items;
2023-03-10 22:48:44 +00:00
final List<WalletNavigationBarItemData> moreItems;
2023-03-10 18:42:45 +00:00
@override
ConsumerState<WalletNavigationBar> createState() =>
_WalletNavigationBarState();
}
class _WalletNavigationBarState extends ConsumerState<WalletNavigationBar> {
static const double horizontalPadding = 16;
final _moreDuration = const Duration(milliseconds: 200);
void _onMorePressed() {
ref.read(walletNavBarMore.state).state =
!ref.read(walletNavBarMore.state).state;
}
@override
Widget build(BuildContext context) {
2023-03-10 22:48:44 +00:00
final width = MediaQuery.of(context).size.width - 40;
final hasMore = widget.moreItems.isNotEmpty;
final buttonCount = widget.items.length + (hasMore ? 1 : 0);
2023-03-10 18:42:45 +00:00
return Stack(
alignment: Alignment.bottomCenter,
children: [
IgnorePointer(
ignoring: !ref.read(walletNavBarMore.state).state,
child: GestureDetector(
onTap: () {
if (ref.read(walletNavBarMore.state).state) {
ref.read(walletNavBarMore.state).state = false;
}
},
child: AnimatedOpacity(
opacity: ref.watch(walletNavBarMore.state).state ? 1 : 0,
duration: _moreDuration,
child: Container(
color: Colors.black.withOpacity(0.7),
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: horizontalPadding,
right: horizontalPadding,
bottom: horizontalPadding,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
AnimatedScale(
scale: ref.watch(walletNavBarMore.state).state ? 1 : 0,
duration: _moreDuration,
alignment: const Alignment(
0.5,
1.0,
),
child: AnimatedOpacity(
opacity: ref.watch(walletNavBarMore.state).state ? 1 : 0,
duration: _moreDuration,
child: IntrinsicWidth(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
2023-03-10 22:48:44 +00:00
...widget.moreItems.map(
2023-03-10 18:42:45 +00:00
(e) {
return Column(
children: [
WalletNavigationBarMoreItem(data: e),
const SizedBox(
height: 8,
),
],
);
},
),
],
),
),
),
),
Material(
2023-03-17 21:46:49 +00:00
color: Colors.transparent,
2023-03-10 18:42:45 +00:00
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
1000,
),
),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context)
.extension<StackColors>()!
.bottomNavBack,
boxShadow: [
Theme.of(context)
.extension<StackColors>()!
.standardBoxShadow
],
borderRadius: BorderRadius.circular(
1000,
),
),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 6,
2023-03-10 22:48:44 +00:00
horizontal: 20,
2023-03-10 18:42:45 +00:00
),
2023-03-10 22:48:44 +00:00
// 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: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2023-03-10 18:42:45 +00:00
...widget.items.map(
2023-03-10 22:48:44 +00:00
(e) => Expanded(
2023-03-10 18:42:45 +00:00
child: WalletNavigationBarItem(
data: e,
disableDuration: _moreDuration,
),
),
),
2023-03-10 22:48:44 +00:00
if (hasMore)
Expanded(
child: WalletNavigationBarItem(
data: WalletNavigationBarItemData(
icon: AnimatedCrossFade(
firstChild: SvgPicture.asset(
Assets.svg.bars,
width: 20,
height: 20,
color: Theme.of(context)
.extension<StackColors>()!
.bottomNavIconIcon,
),
secondChild: SvgPicture.asset(
Assets.svg.bars,
width: 20,
height: 20,
2023-03-10 18:42:45 +00:00
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
),
2023-03-10 22:48:44 +00:00
crossFadeState: ref
.watch(walletNavBarMore.state)
.state
? CrossFadeState.showSecond
: CrossFadeState.showFirst,
duration: _moreDuration,
2023-03-10 18:42:45 +00:00
),
2023-03-10 22:48:44 +00:00
overrideText: AnimatedCrossFade(
firstChild: Text(
"More",
style: STextStyles.buttonSmall(
context),
),
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,
2023-03-10 18:42:45 +00:00
),
2023-03-10 22:48:44 +00:00
disableDuration: _moreDuration,
2023-03-10 18:42:45 +00:00
),
),
2023-03-10 22:48:44 +00:00
],
),
2023-03-10 18:42:45 +00:00
),
),
),
),
),
],
),
],
),
),
],
);
}
}