| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cake_wallet/routes.dart'; |
| 3 | import 'package:cake_wallet/src/widgets/setting_action_button.dart'; |
| 4 | import 'package:cake_wallet/src/widgets/setting_actions.dart'; |
| 5 | import 'package:cake_wallet/typography.dart'; |
| 6 | import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; |
| 7 | import 'package:flutter/material.dart'; |
| 8 | import 'package:cake_wallet/router.dart' as Router; |
| 9 | |
| 10 | final _settingsNavigatorKey = GlobalKey<NavigatorState>(); |
| 11 | |
| 12 | class DesktopSettingsPage extends StatefulWidget { |
| 13 | const DesktopSettingsPage(this.dashboardViewModel, {super.key}); |
| 14 | |
| 15 | final DashboardViewModel dashboardViewModel; |
| 16 | |
| 17 | @override |
| 18 | State<DesktopSettingsPage> createState() => _DesktopSettingsPageState(); |
| 19 | } |
| 20 | |
| 21 | class _DesktopSettingsPageState extends State<DesktopSettingsPage> { |
| 22 | final int itemCount = SettingActions.all.length; |
| 23 | |
| 24 | int? currentPage; |
| 25 | |
| 26 | void _onItemChange(int index) { |
| 27 | setState(() { |
| 28 | currentPage = index; |
| 29 | }); |
| 30 | } |
| 31 | |
| 32 | @override |
| 33 | Widget build(BuildContext context) { |
| 34 | return Scaffold( |
| 35 | body: Container( |
| 36 | color: Theme.of(context).colorScheme.surface, |
| 37 | height: MediaQuery.of(context).size.height, |
| 38 | child: Row( |
| 39 | children: [ |
| 40 | Expanded( |
| 41 | flex: 1, |
| 42 | child: Column( |
| 43 | crossAxisAlignment: CrossAxisAlignment.start, |
| 44 | children: [ |
| 45 | Padding( |
| 46 | padding: const EdgeInsets.fromLTRB(24, 24, 24, 4), |
| 47 | child: Text( |
| 48 | S.current.settings, |
| 49 | style: textXLarge(), |
| 50 | ), |
| 51 | ), |
| 52 | Expanded( |
| 53 | child: ListView.separated( |
| 54 | padding: EdgeInsets.only(top: 0), |
| 55 | itemBuilder: (_, index) { |
| 56 | final item = SettingActions.all[index]; |
| 57 | |
| 58 | if (!widget.dashboardViewModel.hasSilentPayments && |
| 59 | item.name(context) == S.of(context).silent_payments_settings) { |
| 60 | return Container(); |
| 61 | } |
| 62 | |
| 63 | if ((!widget.dashboardViewModel.isMoneroViewOnly && |
| 64 | item.name(context) == S.of(context).export_outputs) || |
| 65 | (!widget.dashboardViewModel.hasMweb && |
| 66 | item.name(context) == S.of(context).litecoin_mweb_settings)) { |
| 67 | return Container(); |
| 68 | } |
| 69 | |
| 70 | final isLastTile = index == itemCount - 1; |
| 71 | return SettingActionButton( |
| 72 | isLastTile: isLastTile, |
| 73 | selectionActive: currentPage != null, |
| 74 | isSelected: currentPage == index, |
| 75 | isArrowVisible: true, |
| 76 | onTap: () { |
| 77 | if (currentPage != index) { |
| 78 | final settingContext = |
| 79 | _settingsNavigatorKey.currentState?.context ?? context; |
| 80 | item.onTap.call(settingContext); |
| 81 | _onItemChange(index); |
| 82 | } |
| 83 | }, |
| 84 | image: item.image, |
| 85 | title: item.name.call(context), |
| 86 | ); |
| 87 | }, |
| 88 | separatorBuilder: (_, index) => Container( |
| 89 | height: 0.0, |
| 90 | color: Theme.of(context).colorScheme.outlineVariant, |
| 91 | ), |
| 92 | itemCount: itemCount, |
| 93 | ), |
| 94 | ), |
| 95 | ], |
| 96 | ), |
| 97 | ), |
| 98 | Flexible( |
| 99 | flex: 2, |
| 100 | child: ConstrainedBox( |
| 101 | constraints: BoxConstraints(maxWidth: 500), |
| 102 | child: Navigator( |
| 103 | key: _settingsNavigatorKey, |
| 104 | initialRoute: Routes.empty_no_route, |
| 105 | onGenerateRoute: (settings) => Router.createRoute(settings), |
| 106 | onGenerateInitialRoutes: (NavigatorState navigator, String initialRouteName) { |
| 107 | return [ |
| 108 | navigator.widget.onGenerateRoute!(RouteSettings(name: initialRouteName))! |
| 109 | ]; |
| 110 | }, |
| 111 | ), |
| 112 | ), |
| 113 | ) |
| 114 | ], |
| 115 | ), |
| 116 | ), |
| 117 | ); |
| 118 | } |
| 119 | } |