mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-29 14:59:23 +00:00
340 lines
11 KiB
Dart
340 lines
11 KiB
Dart
/*
|
|
* 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
|
|
*
|
|
*/
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
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 '../providers/providers.dart';
|
|
import '../themes/stack_colors.dart';
|
|
import '../utilities/assets.dart';
|
|
import '../utilities/text_styles.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,
|
|
buy,
|
|
notifications,
|
|
addressBook,
|
|
settings,
|
|
support,
|
|
about,
|
|
}
|
|
|
|
class DesktopMenu extends ConsumerStatefulWidget {
|
|
const DesktopMenu({
|
|
super.key,
|
|
this.onSelectionChanged,
|
|
this.onSelectionWillChange,
|
|
});
|
|
|
|
final void Function(DesktopMenuItemId)? onSelectionChanged;
|
|
final void Function(DesktopMenuItemId)? onSelectionWillChange;
|
|
|
|
@override
|
|
ConsumerState<DesktopMenu> createState() => _DesktopMenuState();
|
|
}
|
|
|
|
class _DesktopMenuState extends ConsumerState<DesktopMenu> {
|
|
static const expandedWidth = 225.0;
|
|
static const minimizedWidth = 72.0;
|
|
|
|
final Duration duration = const Duration(milliseconds: 250);
|
|
late final List<DMIController> controllers;
|
|
late final DMIController torButtonController;
|
|
|
|
double _width = expandedWidth;
|
|
bool get _isMinimized => _width < expandedWidth;
|
|
|
|
void updateSelectedMenuItem(DesktopMenuItemId idKey) {
|
|
widget.onSelectionWillChange?.call(idKey);
|
|
|
|
ref.read(currentDesktopMenuItemProvider.state).state = idKey;
|
|
|
|
widget.onSelectionChanged?.call(idKey);
|
|
}
|
|
|
|
void toggleMinimize() {
|
|
final expanded = _width == expandedWidth;
|
|
|
|
for (final e in controllers) {
|
|
e.toggle?.call();
|
|
}
|
|
|
|
torButtonController.toggle?.call();
|
|
|
|
setState(() {
|
|
_width = expanded ? minimizedWidth : expandedWidth;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
controllers = [
|
|
DMIController(),
|
|
DMIController(),
|
|
DMIController(),
|
|
DMIController(),
|
|
DMIController(),
|
|
DMIController(),
|
|
DMIController(),
|
|
DMIController(),
|
|
DMIController(),
|
|
];
|
|
|
|
torButtonController = DMIController();
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
for (final e in controllers) {
|
|
e.dispose();
|
|
}
|
|
torButtonController.dispose();
|
|
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final prefs = ref.watch(prefsChangeNotifierProvider);
|
|
|
|
final showExchange = prefs.enableExchange;
|
|
|
|
return Material(
|
|
color: Theme.of(context).extension<StackColors>()!.popupBG,
|
|
child: AnimatedContainer(
|
|
width: _width,
|
|
duration: duration,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
const SizedBox(
|
|
height: 25,
|
|
),
|
|
AnimatedContainer(
|
|
duration: duration,
|
|
width: _width == expandedWidth ? 70 : 32,
|
|
child: LivingStackIcon(
|
|
onPressed: toggleMinimize,
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 10,
|
|
),
|
|
AnimatedOpacity(
|
|
duration: duration,
|
|
opacity: _width == expandedWidth ? 1 : 0,
|
|
child: SizedBox(
|
|
height: 28,
|
|
child: Text(
|
|
AppConfig.appName,
|
|
style: STextStyles.desktopH2(context).copyWith(
|
|
fontSize: 18,
|
|
height: 23.4 / 18,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(
|
|
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.read(selectedSettingsMenuItemStateProvider.state).state =
|
|
4;
|
|
},
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 40,
|
|
),
|
|
Expanded(
|
|
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(
|
|
key: const ValueKey('myStack'),
|
|
duration: duration,
|
|
icon: const DesktopMyStackIcon(),
|
|
label: "My ${AppConfig.prefix}",
|
|
value: DesktopMenuItemId.myStack,
|
|
onChanged: updateSelectedMenuItem,
|
|
controller: controllers[0],
|
|
isExpandedInitially: !_isMinimized,
|
|
),
|
|
if (AppConfig.hasFeature(AppFeature.swap) &&
|
|
showExchange) ...[
|
|
const SizedBox(
|
|
height: 2,
|
|
),
|
|
DesktopMenuItem(
|
|
key: const ValueKey('swap'),
|
|
duration: duration,
|
|
icon: const DesktopExchangeIcon(),
|
|
label: "Swap",
|
|
value: DesktopMenuItemId.exchange,
|
|
onChanged: updateSelectedMenuItem,
|
|
controller: controllers[1],
|
|
isExpandedInitially: !_isMinimized,
|
|
),
|
|
],
|
|
if (AppConfig.hasFeature(AppFeature.buy) &&
|
|
showExchange) ...[
|
|
const SizedBox(
|
|
height: 2,
|
|
),
|
|
DesktopMenuItem(
|
|
key: const ValueKey('buy'),
|
|
duration: duration,
|
|
icon: const DesktopBuyIcon(),
|
|
label: "Buy crypto",
|
|
value: DesktopMenuItemId.buy,
|
|
onChanged: updateSelectedMenuItem,
|
|
controller: controllers[2],
|
|
isExpandedInitially: !_isMinimized,
|
|
),
|
|
],
|
|
const SizedBox(
|
|
height: 2,
|
|
),
|
|
DesktopMenuItem(
|
|
key: const ValueKey('notifications'),
|
|
duration: duration,
|
|
icon: const DesktopNotificationsIcon(),
|
|
label: "Notifications",
|
|
value: DesktopMenuItemId.notifications,
|
|
onChanged: updateSelectedMenuItem,
|
|
controller: controllers[3],
|
|
isExpandedInitially: !_isMinimized,
|
|
),
|
|
const SizedBox(
|
|
height: 2,
|
|
),
|
|
DesktopMenuItem(
|
|
key: const ValueKey('addressBook'),
|
|
duration: duration,
|
|
icon: const DesktopAddressBookIcon(),
|
|
label: "Address Book",
|
|
value: DesktopMenuItemId.addressBook,
|
|
onChanged: updateSelectedMenuItem,
|
|
controller: controllers[4],
|
|
isExpandedInitially: !_isMinimized,
|
|
),
|
|
const SizedBox(
|
|
height: 2,
|
|
),
|
|
DesktopMenuItem(
|
|
key: const ValueKey('settings'),
|
|
duration: duration,
|
|
icon: const DesktopSettingsIcon(),
|
|
label: "Settings",
|
|
value: DesktopMenuItemId.settings,
|
|
onChanged: updateSelectedMenuItem,
|
|
controller: controllers[5],
|
|
isExpandedInitially: !_isMinimized,
|
|
),
|
|
const SizedBox(
|
|
height: 2,
|
|
),
|
|
DesktopMenuItem(
|
|
key: const ValueKey('support'),
|
|
duration: duration,
|
|
icon: const DesktopSupportIcon(),
|
|
label: "Support",
|
|
value: DesktopMenuItemId.support,
|
|
onChanged: updateSelectedMenuItem,
|
|
controller: controllers[6],
|
|
isExpandedInitially: !_isMinimized,
|
|
),
|
|
const SizedBox(
|
|
height: 2,
|
|
),
|
|
DesktopMenuItem(
|
|
key: const ValueKey('about'),
|
|
duration: duration,
|
|
icon: const DesktopAboutIcon(),
|
|
label: "About",
|
|
value: DesktopMenuItemId.about,
|
|
onChanged: updateSelectedMenuItem,
|
|
controller: controllers[7],
|
|
isExpandedInitially: !_isMinimized,
|
|
),
|
|
const Spacer(),
|
|
if (!Platform.isIOS)
|
|
DesktopMenuItem(
|
|
key: const ValueKey('exit'),
|
|
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();
|
|
// }
|
|
},
|
|
controller: controllers[8],
|
|
isExpandedInitially: !_isMinimized,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Row(
|
|
children: [
|
|
const Spacer(),
|
|
IconButton(
|
|
splashRadius: 18,
|
|
onPressed: toggleMinimize,
|
|
icon: SvgPicture.asset(
|
|
Assets.svg.minimize,
|
|
height: 12,
|
|
width: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|