stack_wallet/lib/pages_desktop_specific/desktop_menu.dart

250 lines
7.7 KiB
Dart
Raw Normal View History

import 'dart:io';
import 'package:flutter/material.dart';
2022-09-16 17:26:12 +00:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.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/utilities/assets.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
2022-11-28 20:25:49 +00:00
import 'package:stackwallet/widgets/desktop/living_stack_icon.dart';
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);
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;
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(),
];
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(
height: 60,
),
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(),
label: "Exchange",
value: DesktopMenuItemId.exchange,
onChanged: updateSelectedMenuItem,
2022-11-28 19:50:55 +00:00
controller: controllers[1],
),
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,
2022-11-28 19:50:55 +00:00
controller: controllers[2],
),
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,
2022-11-28 19:50:55 +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 DesktopSettingsIcon(),
label: "Settings",
value: DesktopMenuItemId.settings,
onChanged: updateSelectedMenuItem,
2022-11-28 19:50:55 +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 DesktopSupportIcon(),
label: "Support",
value: DesktopMenuItemId.support,
onChanged: updateSelectedMenuItem,
2022-11-28 19:50:55 +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 DesktopAboutIcon(),
label: "About",
value: DesktopMenuItemId.about,
onChanged: updateSelectedMenuItem,
2022-11-28 19:50:55 +00:00
controller: controllers[6],
),
const Spacer(),
DesktopMenuItem(
2022-11-28 19:50:55 +00:00
duration: duration,
labelLength: 123,
2022-12-01 16:10:18 +00:00
icon: const DesktopExitIcon(),
label: "Exit",
value: 7,
onChanged: (_) {
// todo: save stuff/ notify before exit?
exit(0);
},
2022-11-28 19:50:55 +00:00
controller: controllers[7],
),
],
),
),
),
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,
),
),
],
),
],
),
),
);
}
}