Skip to content

Commit fd8bb87

Browse files
committed
hide/disable shopinbit/cakepay based on app features flags
1 parent 75733fe commit fd8bb87

6 files changed

Lines changed: 105 additions & 81 deletions

File tree

lib/pages/settings_views/global_settings_view/global_settings_view.dart

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -247,33 +247,37 @@ class GlobalSettingsView extends StatelessWidget {
247247
);
248248
},
249249
),
250-
Consumer(
251-
builder: (_, ref, __) {
252-
final familiarity = ref.watch(
253-
prefsChangeNotifierProvider.select(
254-
(v) => v.familiarity,
255-
),
256-
);
257-
if (familiarity < 6) {
258-
return const SizedBox.shrink();
259-
}
260-
return Column(
261-
children: [
262-
const SizedBox(height: 8),
263-
SettingsListButton(
264-
iconAssetName: Assets.svg.key,
265-
iconSize: 16,
266-
title: "ShopinBit",
267-
onPressed: () {
268-
Navigator.of(context).pushNamed(
269-
ShopInBitSettingsView.routeName,
270-
);
271-
},
250+
if (AppConfig.hasFeature(
251+
AppFeature.shopinBit,
252+
))
253+
Consumer(
254+
builder: (_, ref, __) {
255+
final familiarity = ref.watch(
256+
prefsChangeNotifierProvider.select(
257+
(v) => v.familiarity,
272258
),
273-
],
274-
);
275-
},
276-
),
259+
);
260+
if (familiarity < 6) {
261+
return const SizedBox.shrink();
262+
}
263+
return Column(
264+
children: [
265+
const SizedBox(height: 8),
266+
SettingsListButton(
267+
iconAssetName: Assets.svg.key,
268+
iconSize: 16,
269+
title: "ShopinBit",
270+
onPressed: () {
271+
Navigator.of(context).pushNamed(
272+
ShopInBitSettingsView
273+
.routeName,
274+
);
275+
},
276+
),
277+
],
278+
);
279+
},
280+
),
277281
const SizedBox(height: 8),
278282
SettingsListButton(
279283
iconAssetName: Assets.svg.questionMessage,

lib/pages/wallet_view/wallet_view.dart

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ class _WalletViewState extends ConsumerState<WalletView> {
13481348
);
13491349
},
13501350
),
1351-
if (!viewOnly)
1351+
if (!viewOnly && AppConfig.hasFeature(.shopinBit))
13521352
WalletNavigationBarItemData(
13531353
label: "Services",
13541354
icon: SvgPicture.asset(
@@ -1365,21 +1365,22 @@ class _WalletViewState extends ConsumerState<WalletView> {
13651365
).pushNamed(ServicesView.routeName);
13661366
},
13671367
),
1368-
WalletNavigationBarItemData(
1369-
label: "Gift cards",
1370-
icon: CreditCardIcon(
1371-
height: 20,
1372-
width: 20,
1373-
color: Theme.of(
1374-
context,
1375-
).extension<StackColors>()!.bottomNavIconIcon,
1368+
if (AppConfig.hasFeature(.shopinBit))
1369+
WalletNavigationBarItemData(
1370+
label: "Gift cards",
1371+
icon: CreditCardIcon(
1372+
height: 20,
1373+
width: 20,
1374+
color: Theme.of(
1375+
context,
1376+
).extension<StackColors>()!.bottomNavIconIcon,
1377+
),
1378+
onTap: () {
1379+
Navigator.of(
1380+
context,
1381+
).pushNamed(GiftCardsView.routeName);
1382+
},
13761383
),
1377-
onTap: () {
1378-
Navigator.of(
1379-
context,
1380-
).pushNamed(GiftCardsView.routeName);
1381-
},
1382-
),
13831384
],
13841385
),
13851386
),

lib/pages_desktop_specific/desktop_menu.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,20 @@ class _DesktopMenuState extends ConsumerState<DesktopMenu> {
223223
isExpandedInitially: !_isMinimized,
224224
),
225225
],
226-
const SizedBox(height: 2),
227-
DesktopMenuItem(
228-
key: const ValueKey('services'),
229-
duration: duration,
230-
icon: const DesktopServicesIcon(),
231-
label: "Services",
232-
value: DesktopMenuItemId.services,
233-
onChanged: updateSelectedMenuItem,
234-
controller: controllers[3],
235-
isExpandedInitially: !_isMinimized,
236-
),
226+
if (AppConfig.hasFeature(.shopinBit) ||
227+
AppConfig.hasFeature(.cakePay)) ...[
228+
const SizedBox(height: 2),
229+
DesktopMenuItem(
230+
key: const ValueKey('services'),
231+
duration: duration,
232+
icon: const DesktopServicesIcon(),
233+
label: "Services",
234+
value: DesktopMenuItemId.services,
235+
onChanged: updateSelectedMenuItem,
236+
controller: controllers[3],
237+
isExpandedInitially: !_isMinimized,
238+
),
239+
],
237240
const SizedBox(height: 2),
238241
DesktopMenuItem(
239242
key: const ValueKey('notifications'),

lib/pages_desktop_specific/services/desktop_services_view.dart

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_riverpod/flutter_riverpod.dart';
33
import 'package:flutter_svg/svg.dart';
44

5+
import '../../app_config.dart';
56
import '../../route_generator.dart';
67
import '../../themes/stack_colors.dart';
78
import '../../utilities/assets.dart';
@@ -12,7 +13,22 @@ import '../settings/settings_menu_item.dart';
1213
import 'cakepay/desktop_gift_cards_view.dart';
1314
import 'shopin_bit/desktop_shopinbit_view.dart';
1415

15-
final selectedServicesMenuItemStateProvider = StateProvider<int>((_) => 0);
16+
final _selectedServicesMenuItemStateProvider = StateProvider<_MenuItem?>(
17+
(_) => _labels.firstOrNull,
18+
);
19+
20+
enum _MenuItem {
21+
shopinBit("Services"),
22+
cakePay("Gift Cards");
23+
24+
final String value;
25+
const _MenuItem(this.value);
26+
}
27+
28+
final _labels = [
29+
if (AppConfig.hasFeature(.shopinBit)) _MenuItem.shopinBit,
30+
if (AppConfig.hasFeature(.cakePay)) _MenuItem.cakePay,
31+
];
1632

1733
class DesktopServicesView extends ConsumerStatefulWidget {
1834
const DesktopServicesView({super.key});
@@ -25,22 +41,22 @@ class DesktopServicesView extends ConsumerStatefulWidget {
2541
}
2642

2743
class _DesktopServicesViewState extends ConsumerState<DesktopServicesView> {
28-
final List<String> _labels = const ["Services", "Gift Cards"];
29-
3044
@override
3145
Widget build(BuildContext context) {
32-
final List<Widget> contentViews = [
33-
const Navigator(
34-
key: Key("servicesShopInBitDesktopKey"),
35-
onGenerateRoute: RouteGenerator.generateRoute,
36-
initialRoute: DesktopShopInBitView.routeName,
37-
),
38-
const Navigator(
39-
key: Key("servicesGiftCardsDesktopKey"),
40-
onGenerateRoute: RouteGenerator.generateRoute,
41-
initialRoute: DesktopGiftCardsView.routeName,
42-
),
43-
];
46+
final Map<_MenuItem, Widget> contentViews = {
47+
if (AppConfig.hasFeature(.shopinBit))
48+
.shopinBit: const Navigator(
49+
key: Key("servicesShopInBitDesktopKey"),
50+
onGenerateRoute: RouteGenerator.generateRoute,
51+
initialRoute: DesktopShopInBitView.routeName,
52+
),
53+
if (AppConfig.hasFeature(.cakePay))
54+
.cakePay: const Navigator(
55+
key: Key("servicesGiftCardsDesktopKey"),
56+
onGenerateRoute: RouteGenerator.generateRoute,
57+
initialRoute: DesktopGiftCardsView.routeName,
58+
),
59+
};
4460

4561
return DesktopScaffold(
4662
background: Theme.of(context).extension<StackColors>()!.background,
@@ -68,48 +84,48 @@ class _DesktopServicesViewState extends ConsumerState<DesktopServicesView> {
6884
child: Column(
6985
crossAxisAlignment: CrossAxisAlignment.stretch,
7086
children: [
71-
for (int i = 0; i < _labels.length; i++)
72-
Column(
87+
..._labels.map(
88+
(label) => Column(
7389
mainAxisSize: MainAxisSize.min,
7490
children: [
75-
if (i > 0) const SizedBox(height: 2),
76-
SettingsMenuItem<int>(
91+
SettingsMenuItem<_MenuItem?>(
7792
icon: SvgPicture.asset(
7893
Assets.svg.polygon,
7994
width: 11,
8095
height: 11,
8196
color:
8297
ref
8398
.watch(
84-
selectedServicesMenuItemStateProvider
99+
_selectedServicesMenuItemStateProvider
85100
.state,
86101
)
87102
.state ==
88-
i
103+
label
89104
? Theme.of(context)
90105
.extension<StackColors>()!
91106
.accentColorBlue
92107
: Colors.transparent,
93108
),
94-
label: _labels[i],
95-
value: i,
109+
label: label.value,
110+
value: label,
96111
group: ref
97112
.watch(
98-
selectedServicesMenuItemStateProvider
113+
_selectedServicesMenuItemStateProvider
99114
.state,
100115
)
101116
.state,
102117
onChanged: (newValue) =>
103118
ref
104119
.read(
105-
selectedServicesMenuItemStateProvider
120+
_selectedServicesMenuItemStateProvider
106121
.state,
107122
)
108123
.state =
109124
newValue,
110125
),
111126
],
112127
),
128+
),
113129
],
114130
),
115131
),
@@ -121,8 +137,8 @@ class _DesktopServicesViewState extends ConsumerState<DesktopServicesView> {
121137
Expanded(
122138
child:
123139
contentViews[ref
124-
.watch(selectedServicesMenuItemStateProvider.state)
125-
.state],
140+
.watch(_selectedServicesMenuItemStateProvider.state)
141+
.state]!,
126142
),
127143
],
128144
),

lib/pages_desktop_specific/settings/desktop_settings_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class _DesktopSettingsViewState extends ConsumerState<DesktopSettingsView> {
9494
onGenerateRoute: RouteGenerator.generateRoute,
9595
initialRoute: AdvancedSettings.routeName,
9696
), //advanced
97-
if (familiarity >= 6)
97+
if (AppConfig.hasFeature(.shopinBit) && familiarity >= 6)
9898
const Navigator(
9999
key: Key("settingsShopInBitDesktopKey"),
100100
onGenerateRoute: RouteGenerator.generateRoute,

lib/pages_desktop_specific/settings/settings_menu.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class _SettingsMenuState extends ConsumerState<SettingsMenu> {
4646
"Syncing preferences",
4747
if (AppConfig.hasFeature(AppFeature.themeSelection)) "Appearance",
4848
"Advanced",
49-
if (familiarity >= 6) "ShopinBit",
49+
if (AppConfig.hasFeature(.shopinBit) && familiarity >= 6) "ShopinBit",
5050
];
5151

5252
return Column(

0 commit comments

Comments
 (0)