Files
xianyan/lib/core/layout/right_panel_registry.dart
Developer ca68fe29c7 chore: 批量整理优化项目代码与配置
- 新增模型目录占位文件与翻译类型拆分
- 调整路由配置与桌面端窗口初始化
- 移除多处冗余图表配置项
- 重构右侧面板注册表与三栏布局组件
- 添加智能AppBar、拖拽书签等新功能组件
- 优化安卓编译配置与多平台插件注册
- 新增翻译覆盖率测试与共享组件
- 格式化代码与修复静态分析警告
2026-05-29 10:08:02 +08:00

68 lines
2.0 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/// ============================================================
/// 闲言APP — 右侧面板注册表
/// 创建时间: 2026-05-29
/// 更新时间: 2026-05-29
/// 作用: 管理右侧面板的注册与构建各Tab页面通过注册表提供面板内容
/// 上次更新: 移除dartx依赖使用Dart内置安全集合访问
/// ============================================================
import 'package:flutter/widgets.dart';
typedef RightPanelBuilder = Widget Function(
BuildContext context,
Map<String, dynamic>? args,
);
class RightPanelRegistry {
RightPanelRegistry._();
static final Map<String, RightPanelBuilder> _builders = {};
static void register(String panelId, RightPanelBuilder builder) {
_builders[panelId] = builder;
}
static void registerAll(Map<String, RightPanelBuilder> entries) {
_builders.addAll(entries);
}
static Widget build(String panelId, BuildContext context, {Map<String, dynamic>? args}) {
final builder = _builders[panelId];
if (builder == null) {
return _buildPlaceholder(context, panelId);
}
return builder(context, args);
}
static bool hasPanel(String panelId) => _builders.containsKey(panelId);
static List<String> get registeredIds => _builders.keys.toList();
static String? getPanelIdAtIndex(int index) {
final ids = registeredIds;
return (index >= 0 && index < ids.length) ? ids[index] : null;
}
static RightPanelBuilder? getBuilderAtIndex(int index) {
final id = getPanelIdAtIndex(index);
if (id == null) return null;
return _builders[id];
}
static Widget _buildPlaceholder(BuildContext context, String panelId) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('🚧', style: TextStyle(fontSize: 48)),
const SizedBox(height: 16),
Text(
'面板 "$panelId" 尚未注册',
style: const TextStyle(fontSize: 14),
),
],
),
);
}
}