stack_wallet/lib/pages_desktop_specific/desktop_menu.dart

358 lines
11 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';
2023-09-06 19:43:55 +00:00
import 'package:stackwallet/pages/home_view/sub_widgets/tor_sync_status_changed_event.dart';
2022-12-01 14:48:23 +00:00
import 'package:stackwallet/pages_desktop_specific/desktop_menu_item.dart';
2022-11-14 16:40:31 +00:00
import 'package:stackwallet/providers/desktop/current_desktop_menu_item.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/text_styles.dart';
2022-11-28 20:25:49 +00:00
import 'package:stackwallet/widgets/desktop/living_stack_icon.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({
Key? key,
2022-11-14 16:40:31 +00:00
this.onSelectionChanged,
this.onSelectionWillChange,
2022-09-16 17:26:12 +00:00
}) : super(key: key);
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;
2022-09-16 17:26:12 +00:00
double _width = expandedWidth;
2023-01-14 17:22:48 +00:00
// final _buyDataLoadingService = BuyDataLoadingService();
2023-09-06 19:43:55 +00:00
Widget _buildTorIcon(TorSyncStatus status) {
switch (status) {
case TorSyncStatus.unableToSync:
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
Assets.svg.tor,
2023-09-06 20:26:04 +00:00
color: Theme.of(context).extension<StackColors>()!.textSubtitle3,
2023-09-06 19:43:55 +00:00
width: 20,
height: 20,
),
Text(
"\tDisconnected",
style: STextStyles.smallMed12(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
2023-09-06 20:26:04 +00:00
.textSubtitle3),
2023-09-06 19:43:55 +00:00
)
],
);
case TorSyncStatus.synced:
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
Assets.svg.tor,
color:
Theme.of(context).extension<StackColors>()!.accentColorGreen,
width: 20,
height: 20,
),
Text(
"\tConnected",
style: STextStyles.smallMed12(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.accentColorGreen),
)
],
);
case TorSyncStatus.syncing:
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SvgPicture.asset(
Assets.svg.tor,
color:
Theme.of(context).extension<StackColors>()!.accentColorYellow,
width: 20,
height: 20,
),
Text(
"\tConnecting",
style: STextStyles.smallMed12(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.accentColorYellow),
)
],
);
}
}
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;
for (var e in controllers) {
e.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
];
super.initState();
}
@override
void dispose() {
for (var e in controllers) {
e.dispose();
}
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(
"Stack Wallet",
style: STextStyles.desktopH2(context).copyWith(
fontSize: 18,
height: 23.4 / 18,
),
),
),
),
const SizedBox(
2023-09-06 19:43:55 +00:00
height: 5,
),
MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
// ref.watch(selectedSettingsMenuItemStateProvider.state).state =
// 4;
// ref.watch(selectedSettingsMenuItemStateProvider.state).state =
// 5;
// Navigator.of(context).pushNamed(DesktopHomeView.routeName);
},
child: _buildTorIcon(TorSyncStatus.unableToSync)),
),
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 Stack",
value: DesktopMenuItemId.myStack,
onChanged: updateSelectedMenuItem,
2022-11-28 19:50:55 +00:00
controller: controllers[0],
),
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 DesktopExchangeIcon(),
2023-03-10 22:01:34 +00:00
label: "Swap",
value: DesktopMenuItemId.exchange,
onChanged: updateSelectedMenuItem,
2022-11-28 19:50:55 +00:00
controller: controllers[1],
),
const SizedBox(
height: 2,
),
2023-01-04 16:49:13 +00:00
DesktopMenuItem(
duration: duration,
icon: const DesktopBuyIcon(),
label: "Buy crypto",
2023-01-04 16:49:13 +00:00
value: DesktopMenuItemId.buy,
onChanged: updateSelectedMenuItem,
2023-01-04 16:49:13 +00:00
controller: controllers[2],
),
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?
// exit(0);
SystemNavigator.pop();
},
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,
),
),
],
),
],
),
),
);
}
}