434 lines
15 KiB
Dart
434 lines
15 KiB
Dart
/// 左上角品牌按钮 +「EDC易得」设计合集菜单。
|
|
///
|
|
/// 点开左上角 logo:菜单从 logo **下方**下拉展开(不遮挡 logo)。
|
|
/// 菜单由模块注册表驱动:首页入口 + 已开放模块(可进入/新建)+
|
|
/// 未开放模块(灰色显示,无「规划中」字样)+ 底部「软件设置」。
|
|
/// 具体动作由外壳(AppShell)通过 [BrandMenuButton.onCommand] 执行:
|
|
/// 命令为 `_home` / `_settings` / 模块 id。
|
|
library;
|
|
|
|
import 'dart:math' as math;
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../model/models.dart';
|
|
import '../modules/module_registry.dart';
|
|
import '../state/app_controller.dart';
|
|
import '../theme/tokens.dart';
|
|
import '../version.dart';
|
|
import 'app_logo.dart';
|
|
|
|
/// 品牌按钮:logo + 当前模块名,点击在下方弹出合集菜单。
|
|
class BrandMenuButton extends StatelessWidget {
|
|
/// 构造品牌按钮。
|
|
const BrandMenuButton({
|
|
super.key,
|
|
required this.controller,
|
|
required this.onCommand,
|
|
this.scale = 1.0,
|
|
this.compact = false,
|
|
});
|
|
|
|
/// 全局应用控制器。
|
|
final AppController controller;
|
|
|
|
/// 菜单命令回调(`_home` / `_settings` / 模块 id)。
|
|
final Future<void> Function(String cmd) onCommand;
|
|
|
|
/// 工具栏缩放系数(触屏平台整体缩小)。
|
|
final double scale;
|
|
|
|
/// 紧凑布局(隐藏副标题)。
|
|
final bool compact;
|
|
|
|
/// 当前模块名(首页显示「设计合集」)。
|
|
String get _label {
|
|
final EdcModule? m = moduleOf(controller.appMode);
|
|
return m == null ? '设计合集' : '${m.name}设计';
|
|
}
|
|
|
|
/// 构建按钮。
|
|
///
|
|
/// 与工具栏「手绘 / 选择」等分段按钮**等高同形**(圆角矩形):
|
|
/// 固定高度 34×scale、圆角 10、内容垂直居中。
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final Tokens t = context.tok;
|
|
final BorderRadius radius = BorderRadius.circular(10);
|
|
return Tooltip(
|
|
message: 'EDC易得:设计合集',
|
|
child: Material(
|
|
color: t.panel,
|
|
borderRadius: radius,
|
|
child: InkWell(
|
|
onTap: () => _open(context),
|
|
borderRadius: radius,
|
|
hoverColor: t.accent.withValues(alpha: 0.08),
|
|
child: Container(
|
|
height: 34 * scale,
|
|
padding: EdgeInsets.symmetric(horizontal: 9 * scale),
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
borderRadius: radius,
|
|
border: Border.all(color: t.line2),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[
|
|
AppLogo(size: 20 * scale),
|
|
SizedBox(width: 7 * scale),
|
|
Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
_label,
|
|
style: TextStyle(
|
|
color: t.text,
|
|
fontSize: (compact ? 12.5 : 13) * scale,
|
|
fontWeight: FontWeight.w700,
|
|
letterSpacing: 0.5 * scale,
|
|
height: 1.1,
|
|
),
|
|
),
|
|
if (!compact)
|
|
Text(
|
|
'Easy Design Collection',
|
|
style: TextStyle(
|
|
color: t.dim,
|
|
fontSize: 9.5 * scale,
|
|
height: 1.1,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(width: 4 * scale),
|
|
Icon(Icons.arrow_drop_down, color: t.sub, size: 17 * scale),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 弹出合集菜单(logo 下方下拉,不遮挡 logo)。
|
|
Future<void> _open(BuildContext context) async {
|
|
final RenderBox button = context.findRenderObject()! as RenderBox;
|
|
final OverlayState overlay = Overlay.of(context);
|
|
final RenderBox overlayBox =
|
|
overlay.context.findRenderObject()! as RenderBox;
|
|
final Offset tl = button.localToGlobal(Offset.zero, ancestor: overlayBox);
|
|
final Offset br = button.localToGlobal(
|
|
button.size.bottomRight(Offset.zero),
|
|
ancestor: overlayBox);
|
|
const double menuW = 204;
|
|
final double left = tl.dx
|
|
.clamp(8.0, math.max(8.0, overlayBox.size.width - menuW - 8));
|
|
final double top = br.dy + 6;
|
|
final Object? picked = await showGeneralDialog<Object>(
|
|
context: context,
|
|
barrierDismissible: true,
|
|
barrierLabel: '关闭菜单',
|
|
barrierColor: Colors.black.withValues(alpha: 0.06),
|
|
transitionDuration: const Duration(milliseconds: 150),
|
|
pageBuilder: (BuildContext ctx, Animation<double> a1,
|
|
Animation<double> a2) =>
|
|
const SizedBox.shrink(),
|
|
transitionBuilder: (BuildContext ctx, Animation<double> anim,
|
|
Animation<double> sec, Widget child) {
|
|
final Animation<double> curved =
|
|
CurvedAnimation(parent: anim, curve: Curves.easeOutCubic);
|
|
return Stack(
|
|
children: <Widget>[
|
|
Positioned(
|
|
left: left,
|
|
top: top,
|
|
child: FadeTransition(
|
|
opacity: curved,
|
|
child: ScaleTransition(
|
|
scale: Tween<double>(begin: 0.96, end: 1).animate(curved),
|
|
alignment: Alignment.topLeft,
|
|
child: _panel(ctx),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
if (picked is String && context.mounted) {
|
|
await onCommand(picked);
|
|
}
|
|
}
|
|
|
|
/// 菜单底部「软件设置」入口。
|
|
Widget _settingsItem(BuildContext context) {
|
|
final Tokens t = context.tok;
|
|
return InkWell(
|
|
onTap: () => Navigator.of(context).pop('_settings'),
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Container(
|
|
width: 30,
|
|
height: 30,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: t.panel2,
|
|
borderRadius: BorderRadius.circular(8),
|
|
border: Border.all(color: t.line),
|
|
),
|
|
child: Icon(Icons.settings_outlined, size: 17, color: t.sub),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text('软件设置',
|
|
style: TextStyle(
|
|
color: t.text,
|
|
fontSize: 12.5,
|
|
fontWeight: FontWeight.w600,
|
|
)),
|
|
Text('外观 · 网格 · 更新',
|
|
style: TextStyle(color: t.dim, fontSize: 10.5)),
|
|
],
|
|
),
|
|
),
|
|
Icon(Icons.chevron_right, size: 16, color: t.dim),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 菜单面板(品牌头部 + 首页 + 模块注册表 + 未开放模块 + 软件设置)。
|
|
Widget _panel(BuildContext context) {
|
|
final Tokens t = context.tok;
|
|
final bool atHome = controller.appMode == AppMode.home;
|
|
final String? curId = moduleOf(controller.appMode)?.id;
|
|
final double maxH = math.max(
|
|
180,
|
|
MediaQuery.sizeOf(context).height - 120,
|
|
);
|
|
return Material(
|
|
color: t.dialog,
|
|
elevation: 14,
|
|
borderRadius: BorderRadius.circular(14),
|
|
child: Container(
|
|
width: 204,
|
|
constraints: BoxConstraints(maxHeight: maxH),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(14),
|
|
border: Border.all(color: t.line2),
|
|
),
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.symmetric(vertical: 6),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(12, 6, 12, 8),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Text('EDC易得',
|
|
style: TextStyle(
|
|
color: t.text,
|
|
fontSize: 12.5,
|
|
fontWeight: FontWeight.w700,
|
|
)),
|
|
const Spacer(),
|
|
Text('v$kAppVersion',
|
|
style: TextStyle(color: t.dim, fontSize: 10)),
|
|
],
|
|
),
|
|
),
|
|
Divider(height: 1, thickness: 1, color: t.line),
|
|
const SizedBox(height: 6),
|
|
// 首页(空白启动工作台)。
|
|
_homeItem(context, atHome),
|
|
const SizedBox(height: 6),
|
|
Divider(height: 1, thickness: 1, color: t.line),
|
|
const SizedBox(height: 4),
|
|
// 已开放模块(可通过「设计合集」进入并新建文档)。
|
|
for (final EdcModule m in kModules)
|
|
if (m.available) _item(context, m, current: curId == m.id),
|
|
const SizedBox(height: 6),
|
|
Divider(height: 1, thickness: 1, color: t.line),
|
|
// 未开放模块:仅灰色显示。
|
|
for (final EdcModule m in kModules)
|
|
if (!m.available) _soon(context, m),
|
|
const SizedBox(height: 6),
|
|
Divider(height: 1, thickness: 1, color: t.line),
|
|
const SizedBox(height: 4),
|
|
_settingsItem(context),
|
|
const SizedBox(height: 4),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 「首页」条目。
|
|
Widget _homeItem(BuildContext context, bool current) {
|
|
final Tokens t = context.tok;
|
|
return InkWell(
|
|
onTap: () => Navigator.of(context).pop('_home'),
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Container(
|
|
width: 30,
|
|
height: 30,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: current ? t.accent.withValues(alpha: 0.16) : t.panel2,
|
|
borderRadius: BorderRadius.circular(8),
|
|
border: Border.all(color: current ? t.accent : t.line),
|
|
),
|
|
child:
|
|
Icon(Icons.home_outlined, size: 17, color: current ? t.accent : t.sub),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
'首页',
|
|
style: TextStyle(
|
|
color: t.text,
|
|
fontSize: 12.5,
|
|
fontWeight:
|
|
current ? FontWeight.w700 : FontWeight.w600,
|
|
),
|
|
),
|
|
Text('新建 · 打开 · 最近',
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(color: t.dim, fontSize: 10.5)),
|
|
],
|
|
),
|
|
),
|
|
if (current) Icon(Icons.check_circle, size: 16, color: t.accent),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 已开放模块条目(点按 = 进入该模块并新建文档)。
|
|
Widget _item(
|
|
BuildContext context,
|
|
EdcModule m, {
|
|
required bool current,
|
|
}) {
|
|
final Tokens t = context.tok;
|
|
return InkWell(
|
|
onTap: () => Navigator.of(context).pop(m.id),
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Container(
|
|
width: 30,
|
|
height: 30,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: current
|
|
? t.accent.withValues(alpha: 0.16)
|
|
: Color(m.accent).withValues(alpha: 0.12),
|
|
borderRadius: BorderRadius.circular(8),
|
|
border: Border.all(color: current ? t.accent : t.line),
|
|
),
|
|
child: Icon(m.icon,
|
|
size: 17, color: current ? t.accent : Color(m.accent)),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
'${m.name}设计',
|
|
style: TextStyle(
|
|
color: t.text,
|
|
fontSize: 12.5,
|
|
fontWeight:
|
|
current ? FontWeight.w700 : FontWeight.w600,
|
|
),
|
|
),
|
|
Text(
|
|
m.blurb,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(color: t.dim, fontSize: 10.5),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (current) Icon(Icons.check_circle, size: 16, color: t.accent),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 未开放模块:仅灰色显示(不可点)。
|
|
Widget _soon(BuildContext context, EdcModule m) {
|
|
final Tokens t = context.tok;
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Container(
|
|
width: 26,
|
|
height: 26,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: t.panel2.withValues(alpha: 0.6),
|
|
borderRadius: BorderRadius.circular(7),
|
|
border: Border.all(color: t.line.withValues(alpha: 0.6)),
|
|
),
|
|
child: Icon(m.icon, size: 15, color: t.dim.withValues(alpha: 0.75)),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(m.name,
|
|
style: TextStyle(
|
|
color: t.dim.withValues(alpha: 0.75),
|
|
fontSize: 12,
|
|
)),
|
|
Text(m.blurb,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
color: t.dim.withValues(alpha: 0.55),
|
|
fontSize: 10,
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|