chore: 批量整理优化项目代码与配置
- 新增模型目录占位文件与翻译类型拆分 - 调整路由配置与桌面端窗口初始化 - 移除多处冗余图表配置项 - 重构右侧面板注册表与三栏布局组件 - 添加智能AppBar、拖拽书签等新功能组件 - 优化安卓编译配置与多平台插件注册 - 新增翻译覆盖率测试与共享组件 - 格式化代码与修复静态分析警告
This commit is contained in:
@@ -3,11 +3,12 @@
|
||||
/// 创建时间: 2026-05-29
|
||||
/// 更新时间: 2026-05-29
|
||||
/// 作用: 宽屏时垂直导航栏,窄屏时底部导航栏,支持4种停靠位置
|
||||
/// 上次更新: 适配Riverpod 3.0统一Provider
|
||||
/// 上次更新: 集成bitsdojo_window桌面端窗口控制按钮(顶部导航栏)
|
||||
/// ============================================================
|
||||
|
||||
import 'dart:ui';
|
||||
import 'package:badges/badges.dart' as badges;
|
||||
import 'package:bitsdojo_window/bitsdojo_window.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
@@ -15,6 +16,7 @@ import '../providers/split_view_provider.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../theme/app_spacing.dart';
|
||||
import '../theme/glass_tokens.dart';
|
||||
import '../utils/platform/platform_utils.dart' as pu;
|
||||
import '../../features/discover/providers/chat_provider.dart';
|
||||
import '../../features/mine/settings/providers/theme_settings_provider.dart';
|
||||
import '../../shared/widgets/animation/tab_icon_sprite.dart';
|
||||
@@ -34,8 +36,10 @@ class AdaptiveNavBar extends ConsumerWidget {
|
||||
final splitState = ref.watch(splitViewProvider);
|
||||
final position = splitState.navBarPosition;
|
||||
return switch (position) {
|
||||
NavBarPosition.left || NavBarPosition.right => _buildVertical(context, ref),
|
||||
NavBarPosition.top || NavBarPosition.bottom => _buildHorizontal(context, ref),
|
||||
NavBarPosition.left ||
|
||||
NavBarPosition.right => _buildVertical(context, ref),
|
||||
NavBarPosition.top ||
|
||||
NavBarPosition.bottom => _buildHorizontal(context, ref),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,7 +71,6 @@ class AdaptiveNavBar extends ConsumerWidget {
|
||||
curve: Curves.easeOut,
|
||||
child: showBadge
|
||||
? badges.Badge(
|
||||
showBadge: true,
|
||||
badgeContent: Text(
|
||||
'',
|
||||
style: TextStyle(
|
||||
@@ -114,8 +117,8 @@ class AdaptiveNavBar extends ConsumerWidget {
|
||||
color: isSelected
|
||||
? (ext.isDark ? ext.textInverse : ext.accent)
|
||||
: (ext.isDark
|
||||
? ext.textInverse.withValues(alpha: 0.38)
|
||||
: const Color(0xFFAEAEB2)),
|
||||
? ext.textInverse.withValues(alpha: 0.38)
|
||||
: const Color(0xFFAEAEB2)),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -161,6 +164,210 @@ class AdaptiveNavBar extends ConsumerWidget {
|
||||
}
|
||||
|
||||
Widget _buildHorizontal(BuildContext context, WidgetRef ref) {
|
||||
return const SizedBox.shrink();
|
||||
final ext = AppTheme.ext(context);
|
||||
final settings = ref.watch(themeSettingsProvider);
|
||||
final unreadCount = ref.watch(chatProvider).unreadCount;
|
||||
final animIntensity = settings.animationIntensity.durationMultiplier;
|
||||
final expressionStyle = settings.tabExpressionStyle;
|
||||
final characterId = settings.tabCharacterStyleId;
|
||||
final splitState = ref.watch(splitViewProvider);
|
||||
final isTop = splitState.navBarPosition == NavBarPosition.top;
|
||||
|
||||
Widget buildTab(TabSpriteType type, int index, String label) {
|
||||
final isSelected = index == currentIndex;
|
||||
final showBadge = index == 1 && unreadCount > 0;
|
||||
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => onTabSelected(index),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AnimatedScale(
|
||||
scale: isSelected ? 1.08 : 1.0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
child: showBadge
|
||||
? badges.Badge(
|
||||
badgeContent: Text(
|
||||
'',
|
||||
style: TextStyle(
|
||||
color: ext.textOnAccent,
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
badgeStyle: const badges.BadgeStyle(
|
||||
badgeColor: CupertinoColors.systemRed,
|
||||
padding: EdgeInsets.all(3),
|
||||
),
|
||||
position: badges.BadgePosition.topEnd(
|
||||
top: -4,
|
||||
end: -6,
|
||||
),
|
||||
child: TabIconSprite(
|
||||
type: type,
|
||||
label: '',
|
||||
isSelected: isSelected,
|
||||
adjacentDirection: 0,
|
||||
animationIntensity: animIntensity,
|
||||
characterId: characterId,
|
||||
eyeScale: expressionStyle.eyeScale,
|
||||
mouthCurve: expressionStyle.mouthCurve,
|
||||
bounceMultiplier: expressionStyle.bounceMultiplier,
|
||||
),
|
||||
)
|
||||
: TabIconSprite(
|
||||
type: type,
|
||||
label: '',
|
||||
isSelected: isSelected,
|
||||
adjacentDirection: 0,
|
||||
animationIntensity: animIntensity,
|
||||
characterId: characterId,
|
||||
eyeScale: expressionStyle.eyeScale,
|
||||
mouthCurve: expressionStyle.mouthCurve,
|
||||
bounceMultiplier: expressionStyle.bounceMultiplier,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400,
|
||||
color: isSelected
|
||||
? (ext.isDark ? ext.textInverse : ext.accent)
|
||||
: (ext.isDark
|
||||
? ext.textInverse.withValues(alpha: 0.38)
|
||||
: const Color(0xFFAEAEB2)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
color: ext.glassColor.withValues(
|
||||
alpha: ext.isDark
|
||||
? GlassTokens.elevatedOpacityDark
|
||||
: GlassTokens.elevatedOpacityLight,
|
||||
),
|
||||
),
|
||||
child: ClipRect(
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(
|
||||
sigmaX: GlassTokens.elevatedBlur * ext.glassBlurMultiplier,
|
||||
sigmaY: GlassTokens.elevatedBlur * ext.glassBlurMultiplier,
|
||||
),
|
||||
child: SafeArea(
|
||||
top: isTop,
|
||||
bottom: !isTop,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
buildTab(TabSpriteType.home, 0, '闲言'),
|
||||
buildTab(TabSpriteType.discover, 1, '发现'),
|
||||
buildTab(TabSpriteType.profile, 2, '我的'),
|
||||
if (isTop && pu.isDesktop) _buildDesktopWindowControls(ext),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 桌面端窗口控制按钮(最小化/最大化/关闭)+ 可拖拽标题栏区域
|
||||
Widget _buildDesktopWindowControls(AppThemeExtension ext) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
WindowTitleBarBox(
|
||||
child: MoveWindow(child: const SizedBox(height: 52, width: 40)),
|
||||
),
|
||||
_WindowControlBtn(
|
||||
icon: CupertinoIcons.minus,
|
||||
ext: ext,
|
||||
onPressed: appWindow.minimize,
|
||||
),
|
||||
_WindowControlBtn(
|
||||
icon: CupertinoIcons.square,
|
||||
ext: ext,
|
||||
iconSize: 12,
|
||||
onPressed: appWindow.maximizeOrRestore,
|
||||
),
|
||||
_WindowControlBtn(
|
||||
icon: CupertinoIcons.xmark,
|
||||
ext: ext,
|
||||
onPressed: appWindow.close,
|
||||
isClose: true,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 窗口控制按钮(最小化/最大化/关闭)
|
||||
class _WindowControlBtn extends StatefulWidget {
|
||||
const _WindowControlBtn({
|
||||
required this.icon,
|
||||
required this.ext,
|
||||
required this.onPressed,
|
||||
this.iconSize = 14,
|
||||
this.isClose = false,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final AppThemeExtension ext;
|
||||
final VoidCallback onPressed;
|
||||
final double iconSize;
|
||||
final bool isClose;
|
||||
|
||||
@override
|
||||
State<_WindowControlBtn> createState() => _WindowControlBtnState();
|
||||
}
|
||||
|
||||
class _WindowControlBtnState extends State<_WindowControlBtn> {
|
||||
bool _isHovering = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ext = widget.ext;
|
||||
final bgColor = _isHovering
|
||||
? (widget.isClose
|
||||
? CupertinoColors.systemRed.withValues(alpha: 0.9)
|
||||
: ext.textHint.withValues(alpha: 0.15))
|
||||
: const Color(0x00000000);
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _isHovering = true),
|
||||
onExit: (_) => setState(() => _isHovering = false),
|
||||
child: GestureDetector(
|
||||
onTap: widget.onPressed,
|
||||
child: Container(
|
||||
width: 46,
|
||||
height: 52,
|
||||
color: bgColor,
|
||||
child: Icon(
|
||||
widget.icon,
|
||||
size: widget.iconSize,
|
||||
color: _isHovering && widget.isClose
|
||||
? CupertinoColors.white
|
||||
: ext.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
/// 创建时间: 2026-05-29
|
||||
/// 更新时间: 2026-05-29
|
||||
/// 作用: 宽屏时左右分屏布局,支持可拖拽分割线、手势隔离、动画过渡
|
||||
/// 上次更新: 适配Riverpod 3.0统一Provider
|
||||
/// 上次更新: 完全移除AnimationController,使用flutter_animate target声明式控制动画方向
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../providers/split_view_provider.dart';
|
||||
import 'panel_cache.dart';
|
||||
import 'split_divider.dart';
|
||||
|
||||
/// 分屏断点:宽度 >= 900px 进入分屏模式
|
||||
@@ -33,38 +35,7 @@ class AdaptiveSplitView extends ConsumerStatefulWidget {
|
||||
ConsumerState<AdaptiveSplitView> createState() => _AdaptiveSplitViewState();
|
||||
}
|
||||
|
||||
class _AdaptiveSplitViewState extends ConsumerState<AdaptiveSplitView>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _panelAnimationController;
|
||||
late Animation<Offset> _slideAnimation;
|
||||
late Animation<double> _fadeAnimation;
|
||||
bool _wasSplitView = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_panelAnimationController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 350),
|
||||
);
|
||||
_slideAnimation =
|
||||
Tween<Offset>(begin: const Offset(1.0, 0.0), end: Offset.zero).animate(
|
||||
CurvedAnimation(
|
||||
parent: _panelAnimationController,
|
||||
curve: Curves.easeInOutCubic,
|
||||
),
|
||||
);
|
||||
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(parent: _panelAnimationController, curve: Curves.easeIn),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_panelAnimationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
class _AdaptiveSplitViewState extends ConsumerState<AdaptiveSplitView> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenWidth = MediaQuery.sizeOf(context).width;
|
||||
@@ -74,21 +45,10 @@ class _AdaptiveSplitViewState extends ConsumerState<AdaptiveSplitView>
|
||||
final splitRatio = splitState.splitRatio;
|
||||
final hasRightContent = splitState.activeRightPanel != null;
|
||||
|
||||
if (isSplitView && hasRightContent) {
|
||||
_panelAnimationController.forward();
|
||||
} else {
|
||||
_panelAnimationController.reverse();
|
||||
}
|
||||
|
||||
if (!isSplitView) {
|
||||
if (_wasSplitView) {
|
||||
_wasSplitView = false;
|
||||
}
|
||||
return widget.leftPanel;
|
||||
}
|
||||
|
||||
_wasSplitView = true;
|
||||
|
||||
final leftWidth = screenWidth * splitRatio;
|
||||
const double dividerWidth = 17.0;
|
||||
final double clampedLeftWidth = leftWidth.clamp(
|
||||
@@ -101,9 +61,11 @@ class _AdaptiveSplitViewState extends ConsumerState<AdaptiveSplitView>
|
||||
children: [
|
||||
SizedBox(
|
||||
width: clampedLeftWidth,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (_) => true,
|
||||
child: widget.leftPanel,
|
||||
child: KeepAlivePanelWrapper(
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (_) => true,
|
||||
child: widget.leftPanel,
|
||||
),
|
||||
),
|
||||
),
|
||||
SplitDivider(
|
||||
@@ -120,15 +82,20 @@ class _AdaptiveSplitViewState extends ConsumerState<AdaptiveSplitView>
|
||||
widget.minRightWidth,
|
||||
screenWidth - widget.minLeftWidth - dividerWidth,
|
||||
),
|
||||
child: SlideTransition(
|
||||
position: _slideAnimation,
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (_) => true,
|
||||
child: widget.rightPanel,
|
||||
),
|
||||
),
|
||||
child: KeepAlivePanelWrapper(
|
||||
child:
|
||||
NotificationListener<ScrollNotification>(
|
||||
onNotification: (_) => true,
|
||||
child: widget.rightPanel,
|
||||
)
|
||||
.animate(target: hasRightContent ? 1.0 : 0.0)
|
||||
.slideX(
|
||||
begin: 1.0,
|
||||
end: 0.0,
|
||||
duration: 350.ms,
|
||||
curve: Curves.easeInOutCubic,
|
||||
)
|
||||
.fadeIn(duration: 200.ms),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
// 创建时间: 2026-04-20
|
||||
// 更新时间: 2026-05-29
|
||||
// 作用: ShellRoute 布局壳,宽屏分屏 + 窄屏底部导航
|
||||
// 上次更新: 集成宽屏分屏布局AdaptiveSplitView+AdaptiveNavBar
|
||||
// 上次更新: 桌面端键盘快捷键(Ctrl+1/2/3切换Tab,Ctrl+W关闭面板)+集成SmartAppBar
|
||||
// ============================================================
|
||||
|
||||
import 'package:badges/badges.dart' as badges;
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:xianyan/core/utils/platform/platform_utils.dart' as pu;
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -28,6 +29,8 @@ import 'adaptive_split_view.dart';
|
||||
import 'adaptive_nav_bar.dart';
|
||||
import 'overview_dashboard.dart';
|
||||
import 'right_panel_registry.dart';
|
||||
import 'triple_column_view.dart';
|
||||
import '../../features/mine/profile/presentation/panels/profile_dashboard.dart';
|
||||
|
||||
class AppShell extends ConsumerStatefulWidget {
|
||||
const AppShell({super.key, required this.child});
|
||||
@@ -47,8 +50,8 @@ class _AppShellState extends ConsumerState<AppShell> {
|
||||
final int currentIndex = widget.child.currentIndex;
|
||||
final screenWidth = MediaQuery.sizeOf(context).width;
|
||||
final splitState = ref.watch(splitViewProvider);
|
||||
final isWidescreen = screenWidth >= kSplitViewBreakpoint &&
|
||||
splitState.splitViewEnabled;
|
||||
final isWidescreen =
|
||||
screenWidth >= kSplitViewBreakpoint && splitState.splitViewEnabled;
|
||||
|
||||
if (AppShell._isOhos) {
|
||||
Log.i(
|
||||
@@ -80,53 +83,93 @@ class _AppShellState extends ConsumerState<AppShell> {
|
||||
final splitState = ref.watch(splitViewProvider);
|
||||
final navBarPosition = splitState.navBarPosition;
|
||||
final isNavBarVertical =
|
||||
navBarPosition == NavBarPosition.left || navBarPosition == NavBarPosition.right;
|
||||
navBarPosition == NavBarPosition.left ||
|
||||
navBarPosition == NavBarPosition.right;
|
||||
final screenWidth = MediaQuery.sizeOf(context).width;
|
||||
final isTripleColumn =
|
||||
screenWidth >= kTripleColumnBreakpoint &&
|
||||
splitState.thirdPanelContent != null;
|
||||
|
||||
Widget navBar = AdaptiveNavBar(
|
||||
final Widget navBar = AdaptiveNavBar(
|
||||
currentIndex: currentIndex,
|
||||
onTabSelected: (index) => _onTabTap(context, index),
|
||||
);
|
||||
|
||||
Widget splitView = AdaptiveSplitView(
|
||||
leftPanel: RepaintBoundary(child: widget.child),
|
||||
rightPanel: _buildRightPanel(context),
|
||||
);
|
||||
final Widget splitView = isTripleColumn
|
||||
? TripleColumnView(
|
||||
leftPanel: RepaintBoundary(child: widget.child),
|
||||
centerPanel: _buildRightPanel(context),
|
||||
rightPanel: _buildThirdPanel(context),
|
||||
)
|
||||
: AdaptiveSplitView(
|
||||
leftPanel: RepaintBoundary(child: widget.child),
|
||||
rightPanel: _buildRightPanel(context),
|
||||
);
|
||||
|
||||
if (isNavBarVertical) {
|
||||
final isLeft = navBarPosition == NavBarPosition.left;
|
||||
return CelebrationOverlay(
|
||||
child: PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (didPop) return;
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (isLeft) navBar,
|
||||
Expanded(child: splitView),
|
||||
if (!isLeft) navBar,
|
||||
],
|
||||
),
|
||||
/// 根据导航栏位置构建布局骨架
|
||||
Widget buildLayout() {
|
||||
if (isNavBarVertical) {
|
||||
final isLeft = navBarPosition == NavBarPosition.left;
|
||||
return Scaffold(
|
||||
body: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (isLeft) navBar,
|
||||
Expanded(child: splitView),
|
||||
if (!isLeft) navBar,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final isTop = navBarPosition == NavBarPosition.top;
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
if (isTop) navBar,
|
||||
Expanded(child: splitView),
|
||||
if (!isTop) navBar,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 水平导航栏(顶部/底部)— 暂时使用底部导航
|
||||
return CelebrationOverlay(
|
||||
final Widget body = CelebrationOverlay(
|
||||
child: PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (didPop) return;
|
||||
},
|
||||
child: Scaffold(
|
||||
body: splitView,
|
||||
bottomNavigationBar: navBar,
|
||||
),
|
||||
child: buildLayout(),
|
||||
),
|
||||
);
|
||||
|
||||
/// 桌面端添加键盘快捷键 (Ctrl+1/2/3 切换Tab, Ctrl+W 关闭面板)
|
||||
if (pu.isDesktop) {
|
||||
return Shortcuts(
|
||||
shortcuts: <LogicalKeySet, Intent>{
|
||||
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.digit1):
|
||||
const _SwitchTabIntent(0),
|
||||
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.digit2):
|
||||
const _SwitchTabIntent(1),
|
||||
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.digit3):
|
||||
const _SwitchTabIntent(2),
|
||||
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyW):
|
||||
const _ClosePanelIntent(),
|
||||
},
|
||||
child: Actions(
|
||||
actions: <Type, Action<Intent>>{
|
||||
_SwitchTabIntent: _SwitchTabAction(
|
||||
onSwitch: (index) => _onTabTap(context, index),
|
||||
),
|
||||
_ClosePanelIntent: _ClosePanelAction(ref: ref),
|
||||
},
|
||||
child: Focus(child: body),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
/// 构建右侧面板内容
|
||||
@@ -135,6 +178,9 @@ class _AppShellState extends ConsumerState<AppShell> {
|
||||
final activePanel = splitState.activeRightPanel;
|
||||
|
||||
if (activePanel == null) {
|
||||
if (splitState.currentTab == 2) {
|
||||
return const ProfileDashboard();
|
||||
}
|
||||
return const OverviewDashboard();
|
||||
}
|
||||
|
||||
@@ -145,6 +191,22 @@ class _AppShellState extends ConsumerState<AppShell> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建第三栏面板内容(超宽屏三栏布局)
|
||||
Widget _buildThirdPanel(BuildContext context) {
|
||||
final splitState = ref.watch(splitViewProvider);
|
||||
final thirdPanel = splitState.thirdPanelContent;
|
||||
|
||||
if (thirdPanel == null) {
|
||||
return const OverviewDashboard();
|
||||
}
|
||||
|
||||
return RightPanelRegistry.build(
|
||||
thirdPanel,
|
||||
context,
|
||||
args: splitState.thirdPanelArgs,
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 窄屏布局(原有逻辑)
|
||||
// ============================================================
|
||||
@@ -286,7 +348,7 @@ class _AppShellState extends ConsumerState<AppShell> {
|
||||
},
|
||||
child: Scaffold(
|
||||
extendBody: true,
|
||||
body: Stack(children: [RepaintBoundary(child: widget.child)]),
|
||||
body: _buildNarrowBody(),
|
||||
bottomNavigationBar: bottomBar,
|
||||
),
|
||||
),
|
||||
@@ -294,7 +356,32 @@ class _AppShellState extends ConsumerState<AppShell> {
|
||||
}
|
||||
|
||||
void _onTabTap(BuildContext context, int index) {
|
||||
widget.child.goBranch(index, initialLocation: index == widget.child.currentIndex);
|
||||
widget.child.goBranch(
|
||||
index,
|
||||
initialLocation: index == widget.child.currentIndex,
|
||||
);
|
||||
}
|
||||
|
||||
/// 窄屏布局body:横屏未达分屏断点时居中限宽,竖屏保持原样
|
||||
Widget _buildNarrowBody() {
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
final isLandscapeNarrow =
|
||||
size.width > 600 &&
|
||||
size.width < kSplitViewBreakpoint &&
|
||||
size.height < size.width;
|
||||
|
||||
final content = Stack(children: [RepaintBoundary(child: widget.child)]);
|
||||
|
||||
if (isLandscapeNarrow) {
|
||||
return Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 600),
|
||||
child: content,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
Widget _buildFallbackNavBar(
|
||||
@@ -331,3 +418,44 @@ class _AppShellState extends ConsumerState<AppShell> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 桌面端键盘快捷键 — Intent & Action
|
||||
// ============================================================
|
||||
|
||||
/// 切换Tab意图
|
||||
class _SwitchTabIntent extends Intent {
|
||||
const _SwitchTabIntent(this.index);
|
||||
final int index;
|
||||
}
|
||||
|
||||
/// 关闭面板意图
|
||||
class _ClosePanelIntent extends Intent {
|
||||
const _ClosePanelIntent();
|
||||
}
|
||||
|
||||
/// 切换Tab动作
|
||||
class _SwitchTabAction extends Action<_SwitchTabIntent> {
|
||||
_SwitchTabAction({required this.onSwitch});
|
||||
|
||||
final void Function(int) onSwitch;
|
||||
|
||||
@override
|
||||
Object? invoke(_SwitchTabIntent intent) {
|
||||
onSwitch(intent.index);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// 关闭面板动作
|
||||
class _ClosePanelAction extends Action<_ClosePanelIntent> {
|
||||
_ClosePanelAction({required this.ref});
|
||||
|
||||
final WidgetRef ref;
|
||||
|
||||
@override
|
||||
Object? invoke(_ClosePanelIntent intent) {
|
||||
ref.read(splitViewProvider.notifier).clearActivePanel();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,23 @@
|
||||
/// 创建时间: 2026-05-29
|
||||
/// 更新时间: 2026-05-29
|
||||
/// 作用: 宽屏分屏右侧面板的空状态页面,显示概览信息
|
||||
/// 上次更新: 修复未使用变量警告
|
||||
/// 上次更新: 快捷操作和数据统计添加flutter_staggered_animations交错入场动画
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
import '../theme/app_spacing.dart';
|
||||
import '../../shared/widgets/containers/glass_container.dart';
|
||||
import '../../features/home/providers/home_provider.dart';
|
||||
import '../../features/home/providers/favorite_provider.dart';
|
||||
import '../../features/home/providers/likes_provider.dart';
|
||||
import '../../features/auth/providers/auth_provider.dart';
|
||||
import '../../features/mine/signin/providers/signin_provider.dart';
|
||||
import '../router/app_routes.dart';
|
||||
import '../router/app_nav_extension.dart';
|
||||
|
||||
class OverviewDashboard extends ConsumerWidget {
|
||||
const OverviewDashboard({super.key});
|
||||
@@ -25,13 +33,13 @@ class OverviewDashboard extends ConsumerWidget {
|
||||
children: [
|
||||
_buildGreeting(context),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildTodayRecommend(context),
|
||||
_buildTodayRecommend(context, ref),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildQuickActions(context),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildRecentHistory(context),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildStats(context),
|
||||
_buildStats(context, ref),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
],
|
||||
),
|
||||
@@ -79,8 +87,10 @@ class OverviewDashboard extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTodayRecommend(BuildContext context) {
|
||||
Widget _buildTodayRecommend(BuildContext context, WidgetRef ref) {
|
||||
final ext = AppTheme.ext(context);
|
||||
final homeState = ref.watch(homeProvider);
|
||||
final recommends = homeState.dailySentences;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -96,34 +106,57 @@ class OverviewDashboard extends ConsumerWidget {
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
SizedBox(
|
||||
height: 120,
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: 3,
|
||||
separatorBuilder: (_, __) => const SizedBox(width: AppSpacing.sm),
|
||||
itemBuilder: (context, index) {
|
||||
return GlassContainer(
|
||||
depth: GlassDepth.base,
|
||||
width: 180,
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'📝 示例句子 ${index + 1}',
|
||||
style: TextStyle(fontSize: 13, color: ext.textPrimary),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
child: recommends.isEmpty
|
||||
? GlassContainer(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text('📭', style: TextStyle(fontSize: 28)),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
'暂无推荐内容',
|
||||
style: TextStyle(fontSize: 13, color: ext.textHint),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'—— 作者',
|
||||
style: TextStyle(fontSize: 11, color: ext.textHint),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: recommends.length,
|
||||
separatorBuilder: (_, __) =>
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
itemBuilder: (context, index) {
|
||||
final sentence = recommends[index];
|
||||
return GlassContainer(
|
||||
width: 180,
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
sentence.text,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: ext.textPrimary,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
sentence.author != null
|
||||
? '—— ${sentence.author}'
|
||||
: '—— 佚名',
|
||||
style: TextStyle(fontSize: 11, color: ext.textHint),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -131,15 +164,15 @@ class OverviewDashboard extends ConsumerWidget {
|
||||
|
||||
Widget _buildQuickActions(BuildContext context) {
|
||||
final ext = AppTheme.ext(context);
|
||||
final actions = [
|
||||
('🔍', '搜索'),
|
||||
('⭐', '收藏'),
|
||||
('📖', '稍后读'),
|
||||
('📝', '笔记'),
|
||||
('📊', '统计'),
|
||||
('⚙️', '设置'),
|
||||
('🎨', '主题'),
|
||||
('🔔', '提醒'),
|
||||
final actions = <({String emoji, String label, String route})>[
|
||||
(emoji: '🔍', label: '搜索', route: AppRoutes.search),
|
||||
(emoji: '⭐', label: '收藏', route: AppRoutes.favorites),
|
||||
(emoji: '📖', label: '稍后读', route: AppRoutes.readLater),
|
||||
(emoji: '🕐', label: '历史', route: AppRoutes.history),
|
||||
(emoji: '✅', label: '签到', route: AppRoutes.signin),
|
||||
(emoji: '📊', label: '阅读报告', route: AppRoutes.readingReport),
|
||||
(emoji: '🌤️', label: '每日推荐', route: AppRoutes.dailyCard),
|
||||
(emoji: '⚙️', label: '设置', route: AppRoutes.generalSettings),
|
||||
];
|
||||
|
||||
return Column(
|
||||
@@ -154,32 +187,44 @@ class OverviewDashboard extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Wrap(
|
||||
spacing: AppSpacing.sm,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: actions.map((action) {
|
||||
return GestureDetector(
|
||||
onTap: () {},
|
||||
child: GlassContainer(
|
||||
depth: GlassDepth.base,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(action.$1, style: const TextStyle(fontSize: 16)),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Text(
|
||||
action.$2,
|
||||
style: TextStyle(fontSize: 13, color: ext.textPrimary),
|
||||
AnimationLimiter(
|
||||
child: Wrap(
|
||||
spacing: AppSpacing.sm,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: actions.asMap().entries.map((entry) {
|
||||
return AnimationConfiguration.staggeredList(
|
||||
position: entry.key,
|
||||
duration: const Duration(milliseconds: 375),
|
||||
child: SlideAnimation(
|
||||
verticalOffset: 50.0,
|
||||
child: FadeInAnimation(
|
||||
child: GestureDetector(
|
||||
onTap: () => context.appPush(entry.value.route),
|
||||
child: GlassContainer(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(entry.value.emoji,
|
||||
style: const TextStyle(fontSize: 16)),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Text(
|
||||
entry.value.label,
|
||||
style: TextStyle(
|
||||
fontSize: 13, color: ext.textPrimary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -201,7 +246,6 @@ class OverviewDashboard extends ConsumerWidget {
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
GlassContainer(
|
||||
depth: GlassDepth.base,
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
child: Center(
|
||||
child: Column(
|
||||
@@ -220,13 +264,23 @@ class OverviewDashboard extends ConsumerWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStats(BuildContext context) {
|
||||
Widget _buildStats(BuildContext context, WidgetRef ref) {
|
||||
final ext = AppTheme.ext(context);
|
||||
final authState = ref.watch(authProvider);
|
||||
final favoriteState = ref.watch(favoriteProvider);
|
||||
final likesState = ref.watch(likesProvider);
|
||||
final signinState = ref.watch(signinProvider);
|
||||
|
||||
final readCount = authState.user?.signinDays ?? 0;
|
||||
final favCount = favoriteState.total;
|
||||
final likeCount = likesState.total;
|
||||
final streakDays = signinState.continuous;
|
||||
|
||||
final stats = [
|
||||
('📖', '阅读', '0'),
|
||||
('⭐', '收藏', '0'),
|
||||
('👍', '点赞', '0'),
|
||||
('🔥', '连续', '0天'),
|
||||
('📖', '阅读', '$readCount'),
|
||||
('⭐', '收藏', '$favCount'),
|
||||
('👍', '点赞', '$likeCount'),
|
||||
('🔥', '连续', '$streakDays天'),
|
||||
];
|
||||
|
||||
return Column(
|
||||
@@ -241,36 +295,47 @@ class OverviewDashboard extends ConsumerWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Row(
|
||||
children: stats.map((stat) {
|
||||
return Expanded(
|
||||
child: GlassContainer(
|
||||
depth: GlassDepth.base,
|
||||
padding: const EdgeInsets.all(AppSpacing.sm),
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xs / 2,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(stat.$1, style: const TextStyle(fontSize: 20)),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
stat.$3,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: ext.textPrimary,
|
||||
AnimationLimiter(
|
||||
child: Row(
|
||||
children: stats.asMap().entries.map((entry) {
|
||||
final stat = entry.value;
|
||||
return AnimationConfiguration.staggeredList(
|
||||
position: entry.key,
|
||||
duration: const Duration(milliseconds: 375),
|
||||
child: SlideAnimation(
|
||||
verticalOffset: 50.0,
|
||||
child: FadeInAnimation(
|
||||
child: Expanded(
|
||||
child: GlassContainer(
|
||||
padding: const EdgeInsets.all(AppSpacing.sm),
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xs / 2,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(stat.$1, style: const TextStyle(fontSize: 20)),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
stat.$3,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: ext.textPrimary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
stat.$2,
|
||||
style: TextStyle(fontSize: 11, color: ext.textHint),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
stat.$2,
|
||||
style: TextStyle(fontSize: 11, color: ext.textHint),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
90
lib/core/layout/panel_bookmark.dart
Normal file
90
lib/core/layout/panel_bookmark.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
/// ============================================================
|
||||
/// 闲言APP — 面板书签功能
|
||||
/// 创建时间: 2026-05-29
|
||||
/// 更新时间: 2026-05-29
|
||||
/// 作用: 收藏常用面板组合,一键切换
|
||||
/// 上次更新: 初始创建
|
||||
/// ============================================================
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../storage/kv_storage.dart';
|
||||
|
||||
/// 面板书签数据模型
|
||||
class PanelBookmark {
|
||||
const PanelBookmark({
|
||||
required this.name,
|
||||
required this.tabIndex,
|
||||
required this.panelId,
|
||||
this.panelArgs,
|
||||
});
|
||||
|
||||
final String name;
|
||||
final int tabIndex;
|
||||
final String panelId;
|
||||
final Map<String, dynamic>? panelArgs;
|
||||
|
||||
/// 序列化为JSON
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': name,
|
||||
'tabIndex': tabIndex,
|
||||
'panelId': panelId,
|
||||
'panelArgs': panelArgs,
|
||||
};
|
||||
|
||||
/// 从JSON反序列化
|
||||
factory PanelBookmark.fromJson(Map<String, dynamic> json) => PanelBookmark(
|
||||
name: json['name'] as String,
|
||||
tabIndex: json['tabIndex'] as int,
|
||||
panelId: json['panelId'] as String,
|
||||
panelArgs: json['panelArgs'] as Map<String, dynamic>?,
|
||||
);
|
||||
}
|
||||
|
||||
/// 面板书签状态管理Notifier
|
||||
class PanelBookmarkNotifier extends Notifier<List<PanelBookmark>> {
|
||||
static const _key = 'panel_bookmarks';
|
||||
|
||||
@override
|
||||
List<PanelBookmark> build() {
|
||||
final raw = KvStorage.getString(_key);
|
||||
if (raw == null) return [];
|
||||
try {
|
||||
final list = jsonDecode(raw) as List;
|
||||
return list
|
||||
.map((e) => PanelBookmark.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
} catch (_) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// 添加书签
|
||||
void addBookmark(PanelBookmark bookmark) {
|
||||
state = [...state, bookmark];
|
||||
_save();
|
||||
}
|
||||
|
||||
/// 移除书签
|
||||
void removeBookmark(int index) {
|
||||
if (index < 0 || index >= state.length) return;
|
||||
state = [...state]..removeAt(index);
|
||||
_save();
|
||||
}
|
||||
|
||||
/// 持久化到KvStorage
|
||||
void _save() {
|
||||
KvStorage.setString(
|
||||
_key,
|
||||
jsonEncode(state.map((e) => e.toJson()).toList()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 面板书签Provider
|
||||
final panelBookmarkProvider =
|
||||
NotifierProvider<PanelBookmarkNotifier, List<PanelBookmark>>(
|
||||
PanelBookmarkNotifier.new,
|
||||
);
|
||||
29
lib/core/layout/panel_cache.dart
Normal file
29
lib/core/layout/panel_cache.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
/// ============================================================
|
||||
/// 闲言APP — 面板缓存组件
|
||||
/// 创建时间: 2026-05-29
|
||||
/// 更新时间: 2026-05-29
|
||||
/// 作用: 使用AutomaticKeepAliveClientMixin保持面板状态不被销毁
|
||||
/// 上次更新: 初始创建
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class KeepAlivePanelWrapper extends StatefulWidget {
|
||||
const KeepAlivePanelWrapper({required this.child, super.key});
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<KeepAlivePanelWrapper> createState() => _KeepAlivePanelWrapperState();
|
||||
}
|
||||
|
||||
class _KeepAlivePanelWrapperState extends State<KeepAlivePanelWrapper>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return widget.child;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
/// 创建时间: 2026-05-29
|
||||
/// 更新时间: 2026-05-29
|
||||
/// 作用: 管理右侧面板的注册与构建,各Tab页面通过注册表提供面板内容
|
||||
/// 上次更新: 初始创建
|
||||
/// 上次更新: 移除dartx依赖,使用Dart内置安全集合访问
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
@@ -18,17 +18,14 @@ class 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);
|
||||
}
|
||||
|
||||
/// 构建面板Widget
|
||||
static Widget build(String panelId, BuildContext context, {Map<String, dynamic>? args}) {
|
||||
final builder = _builders[panelId];
|
||||
if (builder == null) {
|
||||
@@ -37,13 +34,21 @@ class RightPanelRegistry {
|
||||
return builder(context, args);
|
||||
}
|
||||
|
||||
/// 是否已注册
|
||||
static bool hasPanel(String panelId) => _builders.containsKey(panelId);
|
||||
|
||||
/// 获取所有已注册的panelId
|
||||
static List<String> get registeredIds => _builders.keys.toList();
|
||||
|
||||
/// 未注册面板的占位Widget
|
||||
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(
|
||||
|
||||
98
lib/core/layout/rive_tab_icon.dart
Normal file
98
lib/core/layout/rive_tab_icon.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
/// ============================================================
|
||||
/// 闲言APP — Rive Tab 动画组件
|
||||
/// 创建时间: 2026-05-29
|
||||
/// 更新时间: 2026-05-29
|
||||
/// 作用: 使用Rive动画替代TabIconSprite,实现更丰富的角色动画
|
||||
/// 上次更新: 初始创建
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:rive/rive.dart';
|
||||
|
||||
/// Rive Tab 动画图标组件
|
||||
///
|
||||
/// 通过 Rive StateMachine 控制选中/未选中状态切换,
|
||||
/// 作为 TabIconSprite 的可选替代方案。
|
||||
/// 需要提供 .riv 资源文件,StateMachine 中需包含
|
||||
/// 名为 `isSelected` 的布尔输入。
|
||||
class RiveTabIcon extends StatefulWidget {
|
||||
const RiveTabIcon({
|
||||
required this.isSelected,
|
||||
required this.assetPath,
|
||||
this.stateMachineName = 'State',
|
||||
this.size = 32,
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// 是否选中
|
||||
final bool isSelected;
|
||||
|
||||
/// Rive 资源路径 (如 'assets/animations/tab_home.riv')
|
||||
final String assetPath;
|
||||
|
||||
/// StateMachine 名称
|
||||
final String stateMachineName;
|
||||
|
||||
/// 图标尺寸
|
||||
final double size;
|
||||
|
||||
@override
|
||||
State<RiveTabIcon> createState() => _RiveTabIconState();
|
||||
}
|
||||
|
||||
class _RiveTabIconState extends State<RiveTabIcon> {
|
||||
SMIInput<bool>? _selectedInput;
|
||||
Artboard? _artboard;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadRive();
|
||||
}
|
||||
|
||||
/// 加载 Rive 文件并初始化 StateMachine
|
||||
Future<void> _loadRive() async {
|
||||
try {
|
||||
final data = await RiveFile.asset(widget.assetPath);
|
||||
final artboard = data.mainArtboard;
|
||||
final controller = StateMachineController.fromArtboard(
|
||||
artboard,
|
||||
widget.stateMachineName,
|
||||
);
|
||||
if (controller != null) {
|
||||
artboard.addController(controller);
|
||||
_selectedInput = controller.findInput<bool>('isSelected');
|
||||
_selectedInput?.value = widget.isSelected;
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() => _artboard = artboard);
|
||||
}
|
||||
} catch (e) {
|
||||
// Rive文件加载失败时静默处理,不影响其他功能
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(RiveTabIcon oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.isSelected != widget.isSelected) {
|
||||
_selectedInput?.value = widget.isSelected;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_artboard == null) {
|
||||
return SizedBox(
|
||||
width: widget.size,
|
||||
height: widget.size,
|
||||
child: const CupertinoActivityIndicator(radius: 8),
|
||||
);
|
||||
}
|
||||
return SizedBox(
|
||||
width: widget.size,
|
||||
height: widget.size,
|
||||
child: Rive(artboard: _artboard!),
|
||||
);
|
||||
}
|
||||
}
|
||||
86
lib/core/layout/smart_app_bar.dart
Normal file
86
lib/core/layout/smart_app_bar.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
/// ============================================================
|
||||
/// 闲言APP — 智能AppBar组件
|
||||
/// 创建时间: 2026-05-29
|
||||
/// 更新时间: 2026-05-29
|
||||
/// 作用: 自动识别宽屏/窄屏,标题在AppBar居中或内容区靠左
|
||||
/// 上次更新: 初始创建
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../layout/adaptive_split_view.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import '../theme/app_typography.dart';
|
||||
|
||||
/// 智能 AppBar 组件
|
||||
///
|
||||
/// 窄屏(< 900px): 使用 CupertinoNavigationBar,标题居中
|
||||
/// 宽屏(>= 900px): 使用内容区头部,标题靠左,更高效利用空间
|
||||
class SmartAppBar extends ConsumerWidget {
|
||||
const SmartAppBar({
|
||||
required this.title,
|
||||
this.actions,
|
||||
this.leading,
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// 标题文本
|
||||
final String title;
|
||||
|
||||
/// 右侧操作按钮
|
||||
final List<Widget>? actions;
|
||||
|
||||
/// 左侧导航按钮
|
||||
final Widget? leading;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final isWidescreen = screenWidth >= kSplitViewBreakpoint;
|
||||
|
||||
if (isWidescreen) {
|
||||
return _buildContentHeader(context);
|
||||
}
|
||||
return _buildCupertinoAppBar(context);
|
||||
}
|
||||
|
||||
/// 窄屏: CupertinoNavigationBar 标题居中
|
||||
Widget _buildCupertinoAppBar(BuildContext context) {
|
||||
final ext = AppTheme.ext(context);
|
||||
return CupertinoNavigationBar(
|
||||
middle: Text(
|
||||
title,
|
||||
style: AppTypography.title3.copyWith(color: ext.textPrimary),
|
||||
),
|
||||
leading: leading,
|
||||
trailing: actions != null
|
||||
? Row(mainAxisSize: MainAxisSize.min, children: actions!)
|
||||
: null,
|
||||
backgroundColor: ext.bgElevated.withValues(alpha: 0.9),
|
||||
border: null,
|
||||
);
|
||||
}
|
||||
|
||||
/// 宽屏: 内容区头部标题靠左
|
||||
Widget _buildContentHeader(BuildContext context) {
|
||||
final ext = AppTheme.ext(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
if (leading != null) leading!,
|
||||
Text(
|
||||
title,
|
||||
style: AppTypography.title2.copyWith(
|
||||
color: ext.textPrimary,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (actions != null) ...actions!,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,14 @@
|
||||
/// 创建时间: 2026-05-29
|
||||
/// 更新时间: 2026-05-29
|
||||
/// 作用: 宽屏分屏的分割线组件,支持拖拽调整比例、hover高亮、触觉反馈
|
||||
/// 上次更新: 初始创建
|
||||
/// 上次更新: 桌面端跳过HapticFeedback触觉反馈(桌面端无振动马达)
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../theme/app_theme.dart';
|
||||
import '../utils/platform/platform_utils.dart' as pu;
|
||||
|
||||
class SplitDivider extends StatefulWidget {
|
||||
const SplitDivider({
|
||||
@@ -42,8 +43,8 @@ class _SplitDividerState extends State<SplitDivider> {
|
||||
final handleColor = _isDragging
|
||||
? ext.accent.withValues(alpha: 0.8)
|
||||
: _isHovering
|
||||
? ext.accent.withValues(alpha: 0.5)
|
||||
: ext.textHint.withValues(alpha: 0.3);
|
||||
? ext.accent.withValues(alpha: 0.5)
|
||||
: ext.textHint.withValues(alpha: 0.3);
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _isHovering = true),
|
||||
@@ -53,9 +54,15 @@ class _SplitDividerState extends State<SplitDivider> {
|
||||
onHorizontalDragStart: _onDragStart,
|
||||
onHorizontalDragUpdate: _onDragUpdate,
|
||||
onHorizontalDragEnd: _onDragEnd,
|
||||
onDoubleTap: () {
|
||||
if (!pu.isDesktop) {
|
||||
HapticFeedback.mediumImpact();
|
||||
}
|
||||
widget.onPositionChanged(0.4);
|
||||
},
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: Container(
|
||||
width: 17,
|
||||
width: 24,
|
||||
alignment: Alignment.center,
|
||||
child: Container(
|
||||
width: 1,
|
||||
@@ -64,7 +71,11 @@ class _SplitDividerState extends State<SplitDivider> {
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 150),
|
||||
curve: Curves.easeOut,
|
||||
width: _isDragging ? 6 : _isHovering ? 4 : 4,
|
||||
width: _isDragging
|
||||
? 6
|
||||
: _isHovering
|
||||
? 4
|
||||
: 4,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: handleColor,
|
||||
@@ -80,7 +91,9 @@ class _SplitDividerState extends State<SplitDivider> {
|
||||
|
||||
void _onDragStart(DragStartDetails details) {
|
||||
setState(() => _isDragging = true);
|
||||
HapticFeedback.selectionClick();
|
||||
if (!pu.isDesktop) {
|
||||
HapticFeedback.selectionClick();
|
||||
}
|
||||
}
|
||||
|
||||
void _onDragUpdate(DragUpdateDetails details) {
|
||||
@@ -89,8 +102,12 @@ class _SplitDividerState extends State<SplitDivider> {
|
||||
final totalWidth = parent.size.width;
|
||||
if (totalWidth <= 0) return;
|
||||
|
||||
final localX = details.globalPosition.dx - parent.localToGlobal(Offset.zero).dx;
|
||||
final newPosition = (localX / totalWidth).clamp(widget.minPosition, widget.maxPosition);
|
||||
final localX =
|
||||
details.globalPosition.dx - parent.localToGlobal(Offset.zero).dx;
|
||||
final newPosition = (localX / totalWidth).clamp(
|
||||
widget.minPosition,
|
||||
widget.maxPosition,
|
||||
);
|
||||
|
||||
widget.onPositionChanged(newPosition);
|
||||
}
|
||||
|
||||
73
lib/core/layout/triple_column_view.dart
Normal file
73
lib/core/layout/triple_column_view.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
/// ============================================================
|
||||
/// 闲言APP — 三栏布局组件
|
||||
/// 创建时间: 2026-05-29
|
||||
/// 更新时间: 2026-05-29
|
||||
/// 作用: 超宽屏(>=1400px)三栏布局:左侧列表+中间详情+右侧辅助面板
|
||||
/// 上次更新: 初始创建
|
||||
/// ============================================================
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'split_divider.dart';
|
||||
|
||||
class TripleColumnView extends ConsumerStatefulWidget {
|
||||
const TripleColumnView({
|
||||
required this.leftPanel,
|
||||
required this.centerPanel,
|
||||
required this.rightPanel,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final Widget leftPanel;
|
||||
final Widget centerPanel;
|
||||
final Widget rightPanel;
|
||||
|
||||
@override
|
||||
ConsumerState<TripleColumnView> createState() => _TripleColumnViewState();
|
||||
}
|
||||
|
||||
class _TripleColumnViewState extends ConsumerState<TripleColumnView> {
|
||||
double _leftRatio = 0.25;
|
||||
double _centerRatio = 0.40;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
final leftWidth = width * _leftRatio;
|
||||
final centerWidth = width * _centerRatio;
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(width: leftWidth, child: widget.leftPanel),
|
||||
SplitDivider(
|
||||
currentPosition: _leftRatio,
|
||||
onPositionChanged: (newRatio) {
|
||||
setState(() {
|
||||
final delta = newRatio - _leftRatio;
|
||||
_leftRatio = newRatio.clamp(0.15, 0.35);
|
||||
_centerRatio = (_centerRatio - delta).clamp(0.25, 0.55);
|
||||
});
|
||||
},
|
||||
minPosition: 0.15,
|
||||
maxPosition: 0.35,
|
||||
),
|
||||
SizedBox(width: centerWidth, child: widget.centerPanel),
|
||||
SplitDivider(
|
||||
currentPosition: _leftRatio + _centerRatio,
|
||||
onPositionChanged: (newRatio) {
|
||||
setState(() {
|
||||
final combinedRatio = newRatio;
|
||||
_centerRatio =
|
||||
(combinedRatio - _leftRatio).clamp(0.25, 0.55);
|
||||
});
|
||||
},
|
||||
minPosition: _leftRatio + 0.25,
|
||||
maxPosition: _leftRatio + 0.55,
|
||||
),
|
||||
Expanded(child: widget.rightPanel),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user