-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathwallet_home_screen.dart
More file actions
166 lines (155 loc) · 6.29 KB
/
Copy pathwallet_home_screen.dart
File metadata and controls
166 lines (155 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import 'package:bb_mobile/core/themes/colors.dart';
import 'package:bb_mobile/core/widgets/bb_pullable_body.dart';
import 'package:bb_mobile/features/announcements/ui/widgets/announcement_carousel.dart';
import 'package:bb_mobile/features/wallet/presentation/bloc/wallet_bloc.dart';
import 'package:bb_mobile/features/wallet/ui/wallet_router.dart';
import 'package:bb_mobile/features/consolidation/public/consolidation_facade.dart';
import 'package:bb_mobile/features/wallet/ui/widgets/home_errors.dart';
import 'package:bb_mobile/features/wallet/ui/widgets/wallet_bottom_buttons.dart';
import 'package:bb_mobile/features/wallet/ui/widgets/wallet_cards.dart';
import 'package:bb_mobile/features/wallet/ui/widgets/wallet_home_top_section.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
class WalletHomeScreen extends StatefulWidget {
const WalletHomeScreen({super.key});
@override
State<WalletHomeScreen> createState() => _WalletHomeScreenState();
}
class _WalletHomeScreenState extends State<WalletHomeScreen> {
/// Height the pinned Receive/Send bar occupies
static const double _bottomBarHeight = 52.0 + 16.0 * 2;
final GlobalKey<RefreshIndicatorState> _indicatorKey =
GlobalKey<RefreshIndicatorState>();
GoRouter? _router;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
// #2222: a fresh mount triggers a sync — covers cold boot and switching
// back to the wallet tab (the shell rebuilds its child on switch, so this
// screen remounts). The pop-back-to-home path, where this screen stays
// mounted, is handled by the router listener below. The coordinator
// throttles, so a redundant trigger is cheap.
_refreshOnVisible();
// If a refresh was already in flight before this mount (e.g. the
// post-startup WalletStarted refresh), show the spinner over it so the
// user sees activity instead of landing on apparently-static data.
if (context.read<WalletBloc>().state.isRefreshing) {
_indicatorKey.currentState?.show();
}
});
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
// #2222: sync whenever navigation lands back on the wallet home — e.g.
// popping a pushed full-screen route (send/receive/settings) where this
// screen stayed mounted beneath it. A RouteObserver can't see those pops:
// home lives inside the tab shell while those routes are pushed on the root
// navigator, so the pop reveals the *shell*, not home. The router's own
// current location is the reliable signal across that boundary.
final router = GoRouter.of(context);
if (!identical(router, _router)) {
_router?.routerDelegate.removeListener(_onRouteChanged);
_router = router;
router.routerDelegate.addListener(_onRouteChanged);
}
}
void _onRouteChanged() {
if (!mounted) return;
final location = _router?.routerDelegate.currentConfiguration.uri.path;
if (location == WalletRoute.walletHome.path) _refreshOnVisible();
}
@override
void dispose() {
_router?.routerDelegate.removeListener(_onRouteChanged);
super.dispose();
}
void _refreshOnVisible() {
if (!mounted) return;
context.read<WalletBloc>().add(const WalletRefreshed());
}
@override
Widget build(BuildContext context) {
return MultiBlocListener(
listeners: [
BlocListener<WalletBloc, WalletState>(
listenWhen: (previous, current) =>
!previous.isRefreshing && current.isRefreshing,
listener: (context, state) {
// A refresh just started (manual pull, post-activity dispatch,
// env change, etc.) — surface the spinner. RefreshIndicator.show()
// is a no-op if it's already running, so this is safe to combine
// with the initState path.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
_indicatorKey.currentState?.show();
});
},
),
],
child: PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, _) {},
child: Stack(
children: [
// Black background visible only during iOS top overscroll
Positioned(
top: 0,
left: 0,
right: 0,
child: ColoredBox(
color: AppColors.dark.background,
child: const SizedBox(height: 300),
),
),
BBPullableBody(
indicatorKey: _indicatorKey,
onRefresh: () => context.read<WalletBloc>().refresh(),
// Clearance for the bar pinned at the bottom of this Stack, so
// the last wallet card can be scrolled out from under it.
bottomInset:
_bottomBarHeight + MediaQuery.paddingOf(context).bottom,
slivers: [
// Pinned rather than scrolled away: the balance and the
// Buy/Sell/Pay/Transfer actions stay put while the wallet cards
// scroll underneath.
const PinnedHeaderSliver(child: WalletHomeTopSection()),
const SliverToBoxAdapter(child: AnnouncementCarousel()),
const SliverToBoxAdapter(child: HomeWarnings()),
const SliverToBoxAdapter(child: HomeConsolidationBanner()),
SliverToBoxAdapter(
child: WalletCards(
onTap: (w) {
context.pushNamed(
WalletRoute.walletDetail.name,
pathParameters: {'walletId': w.id},
);
},
),
),
],
),
Positioned(
left: 0,
right: 0,
bottom: 0,
child: SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 13.0,
vertical: 16.0,
),
child: WalletBottomButtons(),
),
),
),
],
),
),
);
}
}