stack_wallet/lib/pages_desktop_specific/desktop_menu.dart

317 lines
10 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
2023-03-05 18:35:26 +00:00
import 'dart:io';
import 'package:flutter/material.dart';
2022-12-09 21:50:17 +00:00
import 'package:flutter/services.dart';
2022-09-16 17:26:12 +00:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import '../app_config.dart';
import '../providers/desktop/current_desktop_menu_item.dart';
import '../themes/stack_colors.dart';
import '../utilities/assets.dart';
import '../utilities/text_styles.dart';
import '../wallets/crypto_currency/crypto_currency.dart';
import '../widgets/desktop/desktop_tor_status_button.dart';
import '../widgets/desktop/living_stack_icon.dart';
import 'desktop_menu_item.dart';
import 'settings/settings_menu.dart';
enum DesktopMenuItemId {
myStack,
exchange,
2023-01-04 16:49:13 +00:00
buy,
notifications,
addressBook,
settings,
support,
about,
}
2022-09-16 17:26:12 +00:00
class DesktopMenu extends ConsumerStatefulWidget {
const DesktopMenu({
2024-05-27 23:56:22 +00:00
super.key,
2022-11-14 16:40:31 +00:00
this.onSelectionChanged,
this.onSelectionWillChange,
2024-05-27 23:56:22 +00:00
});
2022-09-16 17:26:12 +00:00
final void Function(DesktopMenuItemId)? onSelectionChanged;
2022-11-14 16:40:31 +00:00
final void Function(DesktopMenuItemId)? onSelectionWillChange;
@override
2022-09-16 17:26:12 +00:00
ConsumerState<DesktopMenu> createState() => _DesktopMenuState();
}
2022-09-16 17:26:12 +00:00
class _DesktopMenuState extends ConsumerState<DesktopMenu> {
static const expandedWidth = 225.0;
static const minimizedWidth = 72.0;
2022-11-28 19:50:55 +00:00
final Duration duration = const Duration(milliseconds: 250);
late final List<DMIController> controllers;
late final DMIController torButtonController;
2022-11-28 19:50:55 +00:00
2022-09-16 17:26:12 +00:00
double _width = expandedWidth;
void updateSelectedMenuItem(DesktopMenuItemId idKey) {
2022-11-14 16:40:31 +00:00
widget.onSelectionWillChange?.call(idKey);
ref.read(currentDesktopMenuItemProvider.state).state = idKey;
widget.onSelectionChanged?.call(idKey);
2022-09-16 17:26:12 +00:00
}
void toggleMinimize() {
2022-11-28 19:50:55 +00:00
final expanded = _width == expandedWidth;
2024-05-27 23:56:22 +00:00
for (final e in controllers) {
2022-11-28 19:50:55 +00:00
e.toggle?.call();
}
torButtonController.toggle?.call();
2022-09-16 17:26:12 +00:00
setState(() {
2022-11-28 19:50:55 +00:00
_width = expanded ? minimizedWidth : expandedWidth;
2022-09-16 17:26:12 +00:00
});
}
2022-11-28 19:50:55 +00:00
@override
void initState() {
controllers = [
DMIController(),
DMIController(),
DMIController(),
DMIController(),
DMIController(),
DMIController(),
DMIController(),
DMIController(),
2023-01-04 16:49:13 +00:00
DMIController(),
2022-11-28 19:50:55 +00:00
];
torButtonController = DMIController();
2022-11-28 19:50:55 +00:00
super.initState();
}
@override
void dispose() {
2024-05-27 23:56:22 +00:00
for (final e in controllers) {
2022-11-28 19:50:55 +00:00
e.dispose();
}
torButtonController.dispose();
2022-11-28 19:50:55 +00:00
super.dispose();
}
@override
Widget build(BuildContext context) {
return Material(
color: Theme.of(context).extension<StackColors>()!.popupBG,
2022-11-28 19:50:55 +00:00
child: AnimatedContainer(
width: _width,
2022-11-28 19:50:55 +00:00
duration: duration,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
2022-11-28 19:50:55 +00:00
const SizedBox(
height: 25,
),
2022-11-28 19:50:55 +00:00
AnimatedContainer(
duration: duration,
2022-09-16 17:26:12 +00:00
width: _width == expandedWidth ? 70 : 32,
2022-11-28 20:25:49 +00:00
child: LivingStackIcon(
onPressed: toggleMinimize,
),
),
const SizedBox(
height: 10,
),
2022-11-28 19:50:55 +00:00
AnimatedOpacity(
duration: duration,
opacity: _width == expandedWidth ? 1 : 0,
child: SizedBox(
height: 28,
child: Text(
AppConfig.appName,
2022-11-28 19:50:55 +00:00
style: STextStyles.desktopH2(context).copyWith(
fontSize: 18,
height: 23.4 / 18,
),
),
),
),
const SizedBox(
2023-09-06 19:43:55 +00:00
height: 5,
),
AnimatedContainer(
duration: duration,
width: _width == expandedWidth
? _width - 32 // 16 padding on either side
: _width - 16, // 8 padding on either side
child: DesktopTorStatusButton(
transitionDuration: duration,
controller: torButtonController,
onPressed: () {
ref.read(currentDesktopMenuItemProvider.state).state =
DesktopMenuItemId.settings;
ref.watch(selectedSettingsMenuItemStateProvider.state).state =
4;
},
),
2023-09-06 19:43:55 +00:00
),
const SizedBox(
height: 40,
),
Expanded(
2022-11-28 19:50:55 +00:00
child: AnimatedContainer(
duration: duration,
width: _width == expandedWidth
? _width - 32 // 16 padding on either side
: _width - 16, // 8 padding on either side
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
DesktopMenuItem(
2022-11-28 19:50:55 +00:00
duration: duration,
2022-12-01 16:10:18 +00:00
icon: const DesktopMyStackIcon(),
label: "My ${AppConfig.prefix}",
value: DesktopMenuItemId.myStack,
onChanged: updateSelectedMenuItem,
2022-11-28 19:50:55 +00:00
controller: controllers[0],
),
if (AppConfig.hasFeature(AppFeature.swap))
const SizedBox(
height: 2,
),
if (AppConfig.hasFeature(AppFeature.swap))
DesktopMenuItem(
duration: duration,
icon: const DesktopExchangeIcon(),
label: "Swap",
value: DesktopMenuItemId.exchange,
onChanged: updateSelectedMenuItem,
controller: controllers[1],
),
if (AppConfig.hasFeature(AppFeature.buy))
const SizedBox(
height: 2,
),
if (AppConfig.hasFeature(AppFeature.buy))
DesktopMenuItem(
duration: duration,
icon: const DesktopBuyIcon(),
label: "Buy crypto",
value: DesktopMenuItemId.buy,
onChanged: updateSelectedMenuItem,
controller: controllers[2],
),
2023-01-04 16:49:13 +00:00
const SizedBox(
height: 2,
),
DesktopMenuItem(
2022-11-28 19:50:55 +00:00
duration: duration,
2022-11-29 17:56:56 +00:00
icon: const DesktopNotificationsIcon(),
label: "Notifications",
value: DesktopMenuItemId.notifications,
onChanged: updateSelectedMenuItem,
2023-01-12 20:13:49 +00:00
controller: controllers[3],
),
const SizedBox(
height: 2,
),
DesktopMenuItem(
2022-11-28 19:50:55 +00:00
duration: duration,
2022-12-01 16:10:18 +00:00
icon: const DesktopAddressBookIcon(),
label: "Address Book",
value: DesktopMenuItemId.addressBook,
onChanged: updateSelectedMenuItem,
2023-01-12 20:13:49 +00:00
controller: controllers[4],
),
const SizedBox(
height: 2,
),
DesktopMenuItem(
2022-11-28 19:50:55 +00:00
duration: duration,
2022-12-01 16:10:18 +00:00
icon: const DesktopSettingsIcon(),
label: "Settings",
value: DesktopMenuItemId.settings,
onChanged: updateSelectedMenuItem,
2023-01-12 20:13:49 +00:00
controller: controllers[5],
),
const SizedBox(
height: 2,
),
DesktopMenuItem(
2022-11-28 19:50:55 +00:00
duration: duration,
2022-12-01 16:10:18 +00:00
icon: const DesktopSupportIcon(),
label: "Support",
value: DesktopMenuItemId.support,
onChanged: updateSelectedMenuItem,
2023-01-12 20:13:49 +00:00
controller: controllers[6],
),
const SizedBox(
height: 2,
),
DesktopMenuItem(
2022-11-28 19:50:55 +00:00
duration: duration,
2022-12-01 16:10:18 +00:00
icon: const DesktopAboutIcon(),
label: "About",
value: DesktopMenuItemId.about,
onChanged: updateSelectedMenuItem,
2023-01-12 20:13:49 +00:00
controller: controllers[7],
),
const Spacer(),
2023-03-05 18:35:26 +00:00
if (!Platform.isIOS)
DesktopMenuItem(
duration: duration,
labelLength: 123,
icon: const DesktopExitIcon(),
label: "Exit",
value: 7,
onChanged: (_) {
// todo: save stuff/ notify before exit?
if (AppConfig.coins
.where((e) => e is Monero || e is Wownero)
.isNotEmpty) {
// hack to insta kill because xmr/wow native lib code sucks
exit(0);
} else {
SystemNavigator.pop();
}
2023-03-05 18:35:26 +00:00
},
controller: controllers[8],
),
],
),
),
),
2022-09-16 17:26:12 +00:00
Row(
children: [
const Spacer(),
IconButton(
splashRadius: 18,
onPressed: toggleMinimize,
icon: SvgPicture.asset(
Assets.svg.minimize,
height: 12,
width: 12,
),
),
],
),
],
),
),
);
}
}