Skip to content

Commit bc6c63f

Browse files
committed
refactor(ui): mobile home view top menu clean up
1 parent caed53d commit bc6c63f

2 files changed

Lines changed: 64 additions & 130 deletions

File tree

lib/pages/home_view/home_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ class _HomeViewState extends ConsumerState<HomeView> {
491491
previous,
492492
next,
493493
) {
494-
if (next is int && next >= 0 && next <= 2) {
494+
if (next >= 0 && next < _children.length) {
495495
// if (next == 1) {
496496
// _exchangeDataLoadingService.loadAll(ref);
497497
// }

lib/pages/home_view/sub_widgets/home_view_button_bar.dart

Lines changed: 63 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -44,144 +44,78 @@ class _HomeViewButtonBarState extends ConsumerState<HomeViewButtonBar> {
4444

4545
@override
4646
Widget build(BuildContext context) {
47-
final selectedIndex = ref.watch(homeViewPageIndexStateProvider.state).state;
4847
return Row(
4948
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
5049
children: [
51-
Expanded(
52-
child: TextButton(
53-
style: selectedIndex == 0
54-
? Theme.of(context)
55-
.extension<StackColors>()!
56-
.getPrimaryEnabledButtonStyle(context)!
57-
.copyWith(
58-
minimumSize:
59-
MaterialStateProperty.all<Size>(const Size(46, 36)),
60-
)
61-
: Theme.of(context)
62-
.extension<StackColors>()!
63-
.getSecondaryEnabledButtonStyle(context)!
64-
.copyWith(
65-
minimumSize:
66-
MaterialStateProperty.all<Size>(const Size(46, 36)),
67-
),
68-
onPressed: () {
69-
FocusScope.of(context).unfocus();
70-
if (selectedIndex != 0) {
71-
ref.read(homeViewPageIndexStateProvider.state).state = 0;
72-
}
73-
},
74-
child: Text(
75-
"Wallets",
76-
style: STextStyles.button(context).copyWith(
77-
fontSize: 14,
78-
color: selectedIndex == 0
79-
? Theme.of(context)
80-
.extension<StackColors>()!
81-
.buttonTextPrimary
82-
: Theme.of(context)
83-
.extension<StackColors>()!
84-
.buttonTextSecondary,
85-
),
86-
),
87-
),
50+
const Expanded(
51+
child: _HomeViewTopMenuButton(index: 0, label: "Wallets"),
8852
),
53+
54+
if (AppConfig.hasFeature(AppFeature.swap)) const SizedBox(width: 8),
8955
if (AppConfig.hasFeature(AppFeature.swap))
90-
const SizedBox(
91-
width: 8,
92-
),
93-
if (AppConfig.hasFeature(AppFeature.swap))
94-
Expanded(
95-
child: TextButton(
96-
style: selectedIndex == 1
97-
? Theme.of(context)
98-
.extension<StackColors>()!
99-
.getPrimaryEnabledButtonStyle(context)!
100-
.copyWith(
101-
minimumSize:
102-
MaterialStateProperty.all<Size>(const Size(46, 36)),
103-
)
104-
: Theme.of(context)
105-
.extension<StackColors>()!
106-
.getSecondaryEnabledButtonStyle(context)!
107-
.copyWith(
108-
minimumSize:
109-
MaterialStateProperty.all<Size>(const Size(46, 36)),
110-
),
111-
onPressed: () async {
112-
FocusScope.of(context).unfocus();
113-
if (selectedIndex != 1) {
114-
ref.read(homeViewPageIndexStateProvider.state).state = 1;
115-
}
116-
// DateTime now = DateTime.now();
117-
// if (ref.read(prefsChangeNotifierProvider).externalCalls) {
118-
// print("loading?");
119-
// await ExchangeDataLoadingService().loadAll(ref);
120-
// }
121-
// if (now.difference(_lastRefreshed) > _refreshInterval) {
122-
// await ExchangeDataLoadingService().loadAll(ref);
123-
// }
124-
},
125-
child: Text(
126-
"Swap",
127-
style: STextStyles.button(context).copyWith(
128-
fontSize: 14,
129-
color: selectedIndex == 1
130-
? Theme.of(context)
131-
.extension<StackColors>()!
132-
.buttonTextPrimary
133-
: Theme.of(context)
134-
.extension<StackColors>()!
135-
.buttonTextSecondary,
136-
),
137-
),
138-
),
139-
),
140-
if (AppConfig.hasFeature(AppFeature.buy))
141-
const SizedBox(
142-
width: 8,
56+
const Expanded(
57+
child: _HomeViewTopMenuButton(index: 1, label: "Swap"),
14358
),
59+
60+
if (AppConfig.hasFeature(AppFeature.buy)) const SizedBox(width: 8),
14461
if (AppConfig.hasFeature(AppFeature.buy))
145-
Expanded(
146-
child: TextButton(
147-
style: selectedIndex == 2
148-
? Theme.of(context)
149-
.extension<StackColors>()!
150-
.getPrimaryEnabledButtonStyle(context)!
151-
.copyWith(
152-
minimumSize:
153-
MaterialStateProperty.all<Size>(const Size(46, 36)),
154-
)
155-
: Theme.of(context)
156-
.extension<StackColors>()!
157-
.getSecondaryEnabledButtonStyle(context)!
158-
.copyWith(
159-
minimumSize:
160-
MaterialStateProperty.all<Size>(const Size(46, 36)),
161-
),
162-
onPressed: () async {
163-
FocusScope.of(context).unfocus();
164-
if (selectedIndex != 2) {
165-
ref.read(homeViewPageIndexStateProvider.state).state = 2;
166-
}
167-
// await BuyDataLoadingService().loadAll(ref);
168-
},
169-
child: Text(
170-
"Buy",
171-
style: STextStyles.button(context).copyWith(
172-
fontSize: 14,
173-
color: selectedIndex == 2
174-
? Theme.of(context)
175-
.extension<StackColors>()!
176-
.buttonTextPrimary
177-
: Theme.of(context)
178-
.extension<StackColors>()!
179-
.buttonTextSecondary,
62+
const Expanded(child: _HomeViewTopMenuButton(index: 2, label: "Buy")),
63+
],
64+
);
65+
}
66+
}
67+
68+
class _HomeViewTopMenuButton extends ConsumerWidget {
69+
const _HomeViewTopMenuButton({
70+
super.key,
71+
required this.index,
72+
required this.label,
73+
});
74+
75+
final int index;
76+
final String label;
77+
78+
@override
79+
Widget build(BuildContext context, WidgetRef ref) {
80+
final selectedIndex = ref.watch(homeViewPageIndexStateProvider);
81+
return TextButton(
82+
style: selectedIndex == index
83+
? Theme.of(context)
84+
.extension<StackColors>()!
85+
.getPrimaryEnabledButtonStyle(context)!
86+
.copyWith(
87+
minimumSize: MaterialStateProperty.all<Size>(
88+
const Size(46, 36),
89+
),
90+
)
91+
: Theme.of(context)
92+
.extension<StackColors>()!
93+
.getSecondaryEnabledButtonStyle(context)!
94+
.copyWith(
95+
minimumSize: MaterialStateProperty.all<Size>(
96+
const Size(46, 36),
97+
),
18098
),
181-
),
182-
),
99+
onPressed: () async {
100+
FocusScope.of(context).unfocus();
101+
if (selectedIndex != index) {
102+
ref.read(homeViewPageIndexStateProvider.state).state = index;
103+
}
104+
},
105+
child: Padding(
106+
padding: const .symmetric(horizontal: 8),
107+
child: Text(
108+
label,
109+
style: STextStyles.button(context).copyWith(
110+
fontSize: 14,
111+
color: selectedIndex == index
112+
? Theme.of(context).extension<StackColors>()!.buttonTextPrimary
113+
: Theme.of(
114+
context,
115+
).extension<StackColors>()!.buttonTextSecondary,
183116
),
184-
],
117+
),
118+
),
185119
);
186120
}
187121
}

0 commit comments

Comments
 (0)