Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
273 changes: 173 additions & 100 deletions lib/new-ui/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:cake_wallet/new-ui/viewmodels/card_customizer/card_customizer_bl
import 'package:cake_wallet/new-ui/widgets/coins_page/action_row/coin_action_row.dart';
import 'package:cake_wallet/new-ui/widgets/coins_page/assets_history/assets_history_section.dart';
import 'package:cake_wallet/new-ui/widgets/coins_page/cards/cards_view.dart';
import 'package:cake_wallet/new-ui/widgets/coins_page/compact_wallet_header.dart';
import 'package:cake_wallet/new-ui/widgets/coins_page/mweb_ad.dart';
import 'package:cake_wallet/new-ui/widgets/coins_page/top_bar_widget/top_bar.dart';
import 'package:cake_wallet/new-ui/widgets/coins_page/unconfirmed_balance_widget.dart';
Expand All @@ -16,6 +17,7 @@ import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
import 'package:cake_wallet/view_model/dashboard/nft_view_model.dart';
import 'package:cake_wallet/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart';
import 'package:cake_wallet/view_model/monero_account_list/monero_account_list_view_model.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -36,17 +38,43 @@ class NewHomePage extends StatefulWidget {
class _NewHomePageState extends State<NewHomePage> {
MoneroAccountListViewModel? accountListViewModel;
bool _lightningMode = false;
final GlobalKey _cardsViewKey = GlobalKey();
final ScrollController _scrollController = ScrollController();
double _triggerOffset = double.infinity;
bool _showHeader = false;

@override
void initState() {
super.initState();
_setAccountViewModel();
_scrollController.addListener(_onScroll);
reaction((_)=>widget.dashboardViewModel.wallet, (_) {
_setAccountViewModel();
setState(() {
_lightningMode = false;
});
});

WidgetsBinding.instance.addPostFrameCallback((_) {
_calculateTriggerOffset();
});
}

void _calculateTriggerOffset() {
final RenderBox? renderBox = _cardsViewKey.currentContext?.findRenderObject() as RenderBox?;
if (renderBox != null) {
setState(() {
_triggerOffset = renderBox.size.height;
});
}
}

void _onScroll() {
if (_scrollController.offset >= _triggerOffset && !_showHeader) {
setState(() => _showHeader = true);
} else if (_scrollController.offset < _triggerOffset && _showHeader) {
setState(() => _showHeader = false);
}
}

void _setAccountViewModel() {
Expand All @@ -58,121 +86,166 @@ class _NewHomePageState extends State<NewHomePage> {
@override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Theme.of(context).colorScheme.surface,
Theme.of(context).colorScheme.surfaceDim,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Theme.of(context).colorScheme.surface,
Theme.of(context).colorScheme.surfaceDim,
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
child: Stack(
children: [
CustomScrollView(
physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
slivers:[
SliverPadding(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
sliver: CupertinoSliverRefreshControl(
refreshTriggerPullDistance: 160,
refreshIndicatorExtent: 90,
onRefresh: () => widget.dashboardViewModel.refreshDashboard(),
child: Stack(
children: [
CustomScrollView(
controller: _scrollController,
physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
slivers: [
SliverPadding(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
sliver: CupertinoSliverRefreshControl(
refreshTriggerPullDistance: 160,
refreshIndicatorExtent: 90,
onRefresh: () => widget.dashboardViewModel.refreshDashboard(),
),
),
),
SliverToBoxAdapter(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
spacing: 24.0,
children: [
TopBar(
dashboardViewModel: widget.dashboardViewModel,
lightningMode: _lightningMode,
onLightningSwitchPress: () {
setState(() {
_lightningMode = !_lightningMode;
});
},
onSettingsButtonPress: () {
CupertinoScaffold.showCupertinoModalBottomSheet(
context: context,
barrierColor: Colors.black.withAlpha(85),
builder: (context) => FractionallySizedBox(
child: Material(
SliverToBoxAdapter(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: [
TopBar(
dashboardViewModel: widget.dashboardViewModel,
lightningMode: _lightningMode,
onLightningSwitchPress: () {
setState(() {
_lightningMode = !_lightningMode;
});
},
onSettingsButtonPress: () {
CupertinoScaffold.showCupertinoModalBottomSheet(
context: context,
barrierColor: Colors.black.withAlpha(85),
builder: (context) => FractionallySizedBox(
child: Material(
child: NewSettingsPage(
dashboardViewModel: widget.dashboardViewModel,
authService: getIt.get<AuthService>(),
authService: getIt.get<AuthService>(),
))),
);
},
);
},
),
SizedBox(height: 24),
Observer(
builder: (_) => WalletInfoBar(
lightningMode: _lightningMode,
hardwareWalletType: widget.dashboardViewModel.wallet.hardwareWalletType,
name: widget.dashboardViewModel.wallet.name,
onCustomizeButtonTap: openCustomizer),
),
SizedBox(height: 24),
],
),
Observer(
builder: (_)=>WalletInfoBar(
lightningMode: _lightningMode,
hardwareWalletType: widget.dashboardViewModel.wallet.hardwareWalletType,
name: widget.dashboardViewModel.wallet.name,
onCustomizeButtonTap: openCustomizer
),
),
SliverToBoxAdapter(
child: CardsView(
key: _cardsViewKey,
showContent: true,
dashboardViewModel: widget.dashboardViewModel,
accountListViewModel: accountListViewModel,
onCompactModeBackgroundCardsTapped: openCustomizer,
lightningMode: _lightningMode,
),
Column(
),
SliverToBoxAdapter(
child: Column(
children: [
CardsView(
key: ValueKey(widget.dashboardViewModel.wallet.name),
SizedBox(height: 10),
UnconfirmedBalanceWidget(
dashboardViewModel: widget.dashboardViewModel,
accountListViewModel: accountListViewModel,
onCompactModeBackgroundCardsTapped: openCustomizer,
lightningMode: _lightningMode,
),
UnconfirmedBalanceWidget(dashboardViewModel: widget.dashboardViewModel,),
SizedBox(height: 24),
Observer(
builder: (_) {
return Column(
children: [
CoinActionRow(
lightningMode: _lightningMode,
showSwap: widget.dashboardViewModel.isEnabledSwapAction,
),
MwebAd(
dashboardViewModel: widget.dashboardViewModel,
),
],
);
},
),
SizedBox(height: 24),
Observer(
builder: (_) => AssetsHistorySection(
nftViewModel: widget.nftViewModel,
dashboardViewModel: widget.dashboardViewModel,
),
),
SizedBox(height: 80.0)
],
),
Observer(
builder: (_) {
return Column(
children: [
CoinActionRow(
lightningMode: _lightningMode,
showSwap: widget.dashboardViewModel.isEnabledSwapAction,),
MwebAd(dashboardViewModel: widget.dashboardViewModel,),
],
);
},
),
Observer(
builder: (_) => AssetsHistorySection(
nftViewModel: widget.nftViewModel,
),
],
),
Container(
height: (MediaQuery.of(context).padding.top),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: <Color>[
Theme.of(context).colorScheme.surface.withAlpha(5),
Theme.of(context).colorScheme.surface.withAlpha(25),
Theme.of(context).colorScheme.surface.withAlpha(50),
Theme.of(context).colorScheme.surface.withAlpha(100),
Theme.of(context).colorScheme.surface.withAlpha(150),
Theme.of(context).colorScheme.surface.withAlpha(175),
Theme.of(context).colorScheme.surface.withAlpha(200),
],
),
),
),
Align(
alignment: Alignment.topCenter,
child: IgnorePointer(
ignoring: !_showHeader,
child: AnimatedOpacity(
duration: const Duration(milliseconds: 200),
opacity: _showHeader ? 1 : 0,
child: Observer(
builder: (_) => CompactWalletHeader(
onHeaderTapped: () => _scrollController.animateTo(0,
duration: Duration(milliseconds: 300), curve: Curves.easeOutCubic),
dashboardViewModel: widget.dashboardViewModel,
accountListViewModel: accountListViewModel,
lightningMode: _lightningMode,
showSwap: widget.dashboardViewModel.isEnabledSwapAction,
),
),
SizedBox(height: 80.0)
],
),
),]
),
Container(
height: (MediaQuery.of(context).padding.top),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: <Color>[
Theme.of(context).colorScheme.surface.withAlpha(5),
Theme.of(context).colorScheme.surface.withAlpha(25),
Theme.of(context).colorScheme.surface.withAlpha(50),
Theme.of(context).colorScheme.surface.withAlpha(100),
Theme.of(context).colorScheme.surface.withAlpha(150),
Theme.of(context).colorScheme.surface.withAlpha(175),
Theme.of(context).colorScheme.surface.withAlpha(200),
],
),
),
),
),
],
),
);
)
],
),
);
}

double getCardBoxHeight() {
final numCards = widget.dashboardViewModel.wallet.type == WalletType.bitcoin
? 1
: widget.dashboardViewModel.cardDesigns.length;
final maxCardHeight = MediaQuery.of(context).size.width * 0.878 * (2/3.2);
final overlapAmount = numCards > 3 ? 5.0 : 60.0;

return maxCardHeight + (numCards-1)*overlapAmount;
}

void openCustomizer() async {
Expand Down Expand Up @@ -215,4 +288,4 @@ class _NewHomePageState extends State<NewHomePage> {
}
widget.dashboardViewModel.loadCardDesigns();
}
}
}
Loading
Loading