2023-03-05 18:35:26 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-09-15 21:38:30 +00:00
|
|
|
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';
|
2022-09-15 21:38:30 +00:00
|
|
|
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';
|
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-11-28 20:25:49 +00:00
|
|
|
import 'package:stackwallet/widgets/desktop/living_stack_icon.dart';
|
2022-09-15 21:38:30 +00:00
|
|
|
|
2022-11-14 15:50:58 +00:00
|
|
|
enum DesktopMenuItemId {
|
|
|
|
myStack,
|
|
|
|
exchange,
|
2023-01-04 16:49:13 +00:00
|
|
|
buy,
|
2022-11-14 15:50:58 +00:00
|
|
|
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;
|
|
|
|
|
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;
|
2022-09-15 21:38:30 +00:00
|
|
|
|
2023-01-14 17:22:48 +00:00
|
|
|
// final _buyDataLoadingService = BuyDataLoadingService();
|
2023-01-12 20:13:29 +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() {
|
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-09-15 21:38:30 +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();
|
|
|
|
}
|
|
|
|
|
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-11-28 19:50:55 +00:00
|
|
|
child: AnimatedContainer(
|
2022-09-15 21:38:30 +00:00
|
|
|
width: _width,
|
2022-11-28 19:50:55 +00:00
|
|
|
duration: duration,
|
2022-09-15 21:38:30 +00:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
2022-11-28 19:50:55 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 25,
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
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,
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
),
|
2022-09-15 21:38:30 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 60,
|
|
|
|
),
|
2022-10-26 21:04:04 +00:00
|
|
|
Expanded(
|
2022-11-28 19:50:55 +00:00
|
|
|
child: AnimatedContainer(
|
|
|
|
duration: duration,
|
2022-10-26 21:04:04 +00:00
|
|
|
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(),
|
2022-10-26 21:04:04 +00:00
|
|
|
label: "My Stack",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.myStack,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
2022-11-28 19:50:55 +00:00
|
|
|
controller: controllers[0],
|
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(
|
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",
|
2022-11-18 18:34:25 +00:00
|
|
|
value: DesktopMenuItemId.exchange,
|
|
|
|
onChanged: updateSelectedMenuItem,
|
2022-11-28 19:50:55 +00:00
|
|
|
controller: controllers[1],
|
2022-11-18 18:34:25 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
2023-01-04 16:49:13 +00:00
|
|
|
DesktopMenuItem(
|
|
|
|
duration: duration,
|
|
|
|
icon: const DesktopBuyIcon(),
|
2023-01-10 21:20:41 +00:00
|
|
|
label: "Buy crypto",
|
2023-01-04 16:49:13 +00:00
|
|
|
value: DesktopMenuItemId.buy,
|
2023-01-13 19:14:56 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
2023-01-04 16:49:13 +00:00
|
|
|
controller: controllers[2],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 2,
|
|
|
|
),
|
2022-10-26 21:04:04 +00:00
|
|
|
DesktopMenuItem(
|
2022-11-28 19:50:55 +00:00
|
|
|
duration: duration,
|
2022-11-29 17:56:56 +00:00
|
|
|
icon: const DesktopNotificationsIcon(),
|
2022-10-26 21:04:04 +00:00
|
|
|
label: "Notifications",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.notifications,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
2023-01-12 20:13:49 +00:00
|
|
|
controller: controllers[3],
|
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(
|
2022-11-28 19:50:55 +00:00
|
|
|
duration: duration,
|
2022-12-01 16:10:18 +00:00
|
|
|
icon: const DesktopAddressBookIcon(),
|
2022-10-26 21:04:04 +00:00
|
|
|
label: "Address Book",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.addressBook,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
2023-01-12 20:13:49 +00:00
|
|
|
controller: controllers[4],
|
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(
|
2022-11-28 19:50:55 +00:00
|
|
|
duration: duration,
|
2022-12-01 16:10:18 +00:00
|
|
|
icon: const DesktopSettingsIcon(),
|
2022-10-26 21:04:04 +00:00
|
|
|
label: "Settings",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.settings,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
2023-01-12 20:13:49 +00:00
|
|
|
controller: controllers[5],
|
2022-10-26 21:04:04 +00:00
|
|
|
),
|
|
|
|
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(),
|
2022-10-26 21:04:04 +00:00
|
|
|
label: "Support",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.support,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
2023-01-12 20:13:49 +00:00
|
|
|
controller: controllers[6],
|
2022-10-26 21:04:04 +00:00
|
|
|
),
|
|
|
|
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(),
|
2022-10-26 21:04:04 +00:00
|
|
|
label: "About",
|
2022-11-14 15:50:58 +00:00
|
|
|
value: DesktopMenuItemId.about,
|
2022-10-26 21:04:04 +00:00
|
|
|
onChanged: updateSelectedMenuItem,
|
2023-01-12 20:13:49 +00:00
|
|
|
controller: controllers[7],
|
2022-10-26 21:04:04 +00:00
|
|
|
),
|
|
|
|
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-10-26 21:04:04 +00:00
|
|
|
],
|
|
|
|
),
|
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
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|