2022-10-26 21:04:04 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-09-15 21:38:30 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-16 17:26:12 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2022-09-15 21:38:30 +00:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
import 'package:stackwallet/pages_desktop_specific/home/desktop_menu_item.dart';
|
2022-11-14 16:40:31 +00:00
|
|
|
import 'package:stackwallet/providers/desktop/current_desktop_menu_item.dart';
|
2022-11-22 22:37:47 +00:00
|
|
|
import 'package:stackwallet/providers/providers.dart';
|
2022-09-15 21:38:30 +00:00
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-09-22 23:48:50 +00:00
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2022-09-15 21:38:30 +00:00
|
|
|
|
2022-11-14 15:50:58 +00:00
|
|
|
enum DesktopMenuItemId {
|
|
|
|
myStack,
|
|
|
|
exchange,
|
|
|
|
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);
|
|
|
|
|
2022-11-14 15:50:58 +00:00
|
|
|
final void Function(DesktopMenuItemId)? onSelectionChanged;
|
2022-11-14 16:40:31 +00:00
|
|
|
final void Function(DesktopMenuItemId)? onSelectionWillChange;
|
2022-09-15 21:38:30 +00:00
|
|
|
|
|
|
|
@override
|
2022-09-16 17:26:12 +00:00
|
|
|
ConsumerState<DesktopMenu> createState() => _DesktopMenuState();
|
2022-09-15 21:38:30 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 17:26:12 +00:00
|
|
|
class _DesktopMenuState extends ConsumerState<DesktopMenu> {
|
|
|
|
static const expandedWidth = 225.0;
|
|
|
|
static const minimizedWidth = 72.0;
|
|
|
|
|
|
|
|
double _width = expandedWidth;
|
2022-09-15 21:38:30 +00:00
|
|
|
|
2022-11-14 15:50:58 +00:00
|
|
|
void updateSelectedMenuItem(DesktopMenuItemId idKey) {
|
2022-11-14 16:40:31 +00:00
|
|
|
widget.onSelectionWillChange?.call(idKey);
|
|
|
|
|
|
|
|
ref.read(currentDesktopMenuItemProvider.state).state = idKey;
|
|
|
|
|
2022-11-14 15:50:58 +00:00
|
|
|
widget.onSelectionChanged?.call(idKey);
|
2022-09-16 17:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void toggleMinimize() {
|
|
|
|
setState(() {
|
|
|
|
_width = _width == expandedWidth ? minimizedWidth : expandedWidth;
|
|
|
|
});
|
2022-09-15 21:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Material(
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context).extension<StackColors>()!.popupBG,
|
2022-09-15 21:38:30 +00:00
|
|
|
child: SizedBox(
|
|
|
|
width: _width,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
2022-09-16 17:26:12 +00:00
|
|
|
SizedBox(
|
|
|
|
height: _width == expandedWidth ? 22 : 25,
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
|
|
|
SizedBox(
|
2022-09-16 17:26:12 +00:00
|
|
|
width: _width == expandedWidth ? 70 : 32,
|
|
|
|
height: _width == expandedWidth ? 70 : 32,
|
2022-09-16 16:23:42 +00:00
|
|
|
child: SvgPicture.asset(
|
2022-09-23 14:33:44 +00:00
|
|
|
Assets.svg.stackIcon(context),
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Text(
|
2022-09-16 17:26:12 +00:00
|
|
|
_width == expandedWidth ? "Stack Wallet" : "",
|
2022-09-22 22:17:21 +00:00
|
|
|
style: STextStyles.desktopH2(context).copyWith(
|
2022-09-15 21:38:30 +00:00
|
|
|
fontSize: 18,
|
|
|
|
height: 23.4 / 18,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 60,
|
|
|
|
),
|
2022-10-26 21:04:04 +00:00
|
|
|
Expanded(
|
|
|
|
child: SizedBox(
|
|
|
|
width: _width == expandedWidth
|
|
|
|
? _width - 32 // 16 padding on either side
|
|
|
|
: _width - 16, // 8 padding on either side
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
DesktopMenuItem(
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.walletDesktop,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
2022-11-14 16:40:31 +00:00
|
|
|
color: DesktopMenuItemId.myStack ==
|
|
|
|
ref
|
|
|
|
.watch(currentDesktopMenuItemProvider.state)
|
|
|
|
.state
|
2022-10-26 21:04:04 +00:00
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
.withOpacity(0.8),
|
|
|
|
),
|
|
|
|
label: "My Stack",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.myStack,
|
2022-11-14 16:40:31 +00:00
|
|
|
group:
|
|
|
|
ref.watch(currentDesktopMenuItemProvider.state).state,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
|
|
|
iconOnly: _width == minimizedWidth,
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
2022-10-26 21:04:04 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
2022-11-18 18:34:25 +00:00
|
|
|
DesktopMenuItem(
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.exchangeDesktop,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
color: DesktopMenuItemId.exchange ==
|
|
|
|
ref
|
|
|
|
.watch(currentDesktopMenuItemProvider.state)
|
|
|
|
.state
|
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorDark
|
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorDark
|
|
|
|
.withOpacity(0.8),
|
|
|
|
),
|
|
|
|
label: "Exchange",
|
|
|
|
value: DesktopMenuItemId.exchange,
|
|
|
|
group:
|
|
|
|
ref.watch(currentDesktopMenuItemProvider.state).state,
|
|
|
|
onChanged: updateSelectedMenuItem,
|
|
|
|
iconOnly: _width == minimizedWidth,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
2022-10-26 21:04:04 +00:00
|
|
|
DesktopMenuItem(
|
|
|
|
icon: SvgPicture.asset(
|
2022-11-22 22:37:47 +00:00
|
|
|
ref.watch(notificationsProvider.select(
|
|
|
|
(value) => value.hasUnreadNotifications))
|
|
|
|
? Assets.svg.bellNew(context)
|
|
|
|
: Assets.svg.bell,
|
2022-10-26 21:04:04 +00:00
|
|
|
width: 20,
|
|
|
|
height: 20,
|
2022-11-22 22:37:47 +00:00
|
|
|
color: ref.watch(notificationsProvider.select(
|
|
|
|
(value) => value.hasUnreadNotifications))
|
|
|
|
? null
|
|
|
|
: DesktopMenuItemId.notifications ==
|
|
|
|
ref
|
|
|
|
.watch(currentDesktopMenuItemProvider
|
|
|
|
.state)
|
|
|
|
.state
|
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorDark
|
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.accentColorDark
|
|
|
|
.withOpacity(0.8),
|
2022-10-26 21:04:04 +00:00
|
|
|
),
|
|
|
|
label: "Notifications",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.notifications,
|
2022-11-14 16:40:31 +00:00
|
|
|
group:
|
|
|
|
ref.watch(currentDesktopMenuItemProvider.state).state,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
|
|
|
iconOnly: _width == minimizedWidth,
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
2022-10-26 21:04:04 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
2022-10-26 21:04:04 +00:00
|
|
|
DesktopMenuItem(
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.addressBookDesktop,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
2022-11-14 16:40:31 +00:00
|
|
|
color: DesktopMenuItemId.addressBook ==
|
|
|
|
ref
|
|
|
|
.watch(currentDesktopMenuItemProvider.state)
|
|
|
|
.state
|
2022-10-26 21:04:04 +00:00
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
.withOpacity(0.8),
|
|
|
|
),
|
|
|
|
label: "Address Book",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.addressBook,
|
2022-11-14 16:40:31 +00:00
|
|
|
group:
|
|
|
|
ref.watch(currentDesktopMenuItemProvider.state).state,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
|
|
|
iconOnly: _width == minimizedWidth,
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
2022-10-26 21:04:04 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
2022-10-26 21:04:04 +00:00
|
|
|
DesktopMenuItem(
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.gear,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
2022-11-14 16:40:31 +00:00
|
|
|
color: DesktopMenuItemId.settings ==
|
|
|
|
ref
|
|
|
|
.watch(currentDesktopMenuItemProvider.state)
|
|
|
|
.state
|
2022-10-26 21:04:04 +00:00
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
.withOpacity(0.8),
|
|
|
|
),
|
|
|
|
label: "Settings",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.settings,
|
2022-11-14 16:40:31 +00:00
|
|
|
group:
|
|
|
|
ref.watch(currentDesktopMenuItemProvider.state).state,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
|
|
|
iconOnly: _width == minimizedWidth,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
|
|
|
DesktopMenuItem(
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.messageQuestion,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
2022-11-14 16:40:31 +00:00
|
|
|
color: DesktopMenuItemId.support ==
|
|
|
|
ref
|
|
|
|
.watch(currentDesktopMenuItemProvider.state)
|
|
|
|
.state
|
2022-10-26 21:04:04 +00:00
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
.withOpacity(0.8),
|
|
|
|
),
|
|
|
|
label: "Support",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.support,
|
2022-11-14 16:40:31 +00:00
|
|
|
group:
|
|
|
|
ref.watch(currentDesktopMenuItemProvider.state).state,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
|
|
|
iconOnly: _width == minimizedWidth,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
|
|
|
DesktopMenuItem(
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.aboutDesktop,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
2022-11-14 16:40:31 +00:00
|
|
|
color: DesktopMenuItemId.about ==
|
|
|
|
ref
|
|
|
|
.watch(currentDesktopMenuItemProvider.state)
|
|
|
|
.state
|
2022-10-26 21:04:04 +00:00
|
|
|
? Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
.withOpacity(0.8),
|
|
|
|
),
|
|
|
|
label: "About",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.about,
|
2022-11-14 16:40:31 +00:00
|
|
|
group:
|
|
|
|
ref.watch(currentDesktopMenuItemProvider.state).state,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
|
|
|
iconOnly: _width == minimizedWidth,
|
|
|
|
),
|
|
|
|
const Spacer(),
|
|
|
|
DesktopMenuItem(
|
|
|
|
icon: SvgPicture.asset(
|
|
|
|
Assets.svg.exitDesktop,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
2022-11-18 18:34:25 +00:00
|
|
|
.accentColorDark
|
2022-10-26 21:04:04 +00:00
|
|
|
.withOpacity(0.8),
|
|
|
|
),
|
|
|
|
label: "Exit",
|
|
|
|
value: 7,
|
2022-11-14 16:40:31 +00:00
|
|
|
group:
|
|
|
|
ref.watch(currentDesktopMenuItemProvider.state).state,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: (_) {
|
|
|
|
// todo: save stuff/ notify before exit?
|
|
|
|
exit(0);
|
|
|
|
},
|
|
|
|
iconOnly: _width == minimizedWidth,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
|
|
|
),
|
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,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2022-10-26 21:04:04 +00:00
|
|
|
),
|
2022-09-15 21:38:30 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|