Files
cutdex/lib/features/editor/layouts/expanded_editor_layout.dart
T
lingjhf abc1868550
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
2026-10-08 18:17:12 +00:00

155 lines
5.2 KiB
Dart

import 'dart:math' as math;
import 'package:flutter/material.dart';
import '../../../shared/layout/workspace_layout_metrics.dart';
import '../../../shared/widgets/workspace_card.dart';
import '../../../shared/widgets/workspace_resize_handle.dart';
class ExpandedEditorLayout extends StatefulWidget {
const ExpandedEditorLayout({
super.key,
required this.preview,
required this.header,
required this.properties,
required this.media,
required this.showMedia,
required this.showProperties,
required this.timelineHeight,
required this.onTimelineHeightChanged,
required this.onTimelineHeightChangeEnd,
required this.timeline,
});
final Widget preview;
final Widget header;
final Widget properties;
final Widget media;
final bool showMedia;
final bool showProperties;
final double? timelineHeight;
final ValueChanged<double> onTimelineHeightChanged;
final VoidCallback onTimelineHeightChangeEnd;
final Widget timeline;
@override
State<ExpandedEditorLayout> createState() => _ExpandedEditorLayoutState();
}
class _ExpandedEditorLayoutState extends State<ExpandedEditorLayout> {
static const gap = WorkspaceLayoutMetrics.desktopSpacing;
late bool _mediaVisited = widget.showMedia;
@override
void didUpdateWidget(covariant ExpandedEditorLayout oldWidget) {
super.didUpdateWidget(oldWidget);
_mediaVisited |= widget.showMedia;
}
Widget _card(String name, Widget child) =>
WorkspaceCard(key: Key('editor-$name-card'), child: child);
@override
Widget build(BuildContext context) => LayoutBuilder(
builder: (context, constraints) {
final maximum = math.max(
0.0,
constraints.maxHeight -
gap -
WorkspaceLayoutMetrics.previewMinimumHeight,
);
final minimum = math.min(
WorkspaceLayoutMetrics.timelineMinimumHeight,
maximum,
);
final timelineHeight =
(widget.timelineHeight ??
constraints.maxHeight *
WorkspaceLayoutMetrics.timelineDefaultHeightFraction)
.clamp(minimum, maximum)
.toDouble();
const mediaWidth = WorkspaceLayoutMetrics.mediaPanelWidth;
final propertiesWidth = widget.showProperties
? WorkspaceLayoutMetrics.propertiesPanelWidth
: 0.0;
return Stack(
fit: StackFit.expand,
children: [
Column(
children: [
Expanded(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (_mediaVisited)
Offstage(
offstage: !widget.showMedia,
child: ExcludeFocus(
excluding: !widget.showMedia,
child: TickerMode(
enabled: widget.showMedia,
child: SizedBox(
key: const Key('editor-media-region'),
width: mediaWidth,
child: _card('media', widget.media),
),
),
),
),
if (widget.showMedia) const SizedBox(width: gap),
Expanded(
child: _card(
'preview',
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
widget.header,
Expanded(child: widget.preview),
],
),
),
),
if (widget.showProperties) ...[
const SizedBox(
key: Key('editor-properties-divider'),
width: gap,
),
SizedBox(
key: const Key('editor-properties-region'),
width: propertiesWidth,
child: _card('properties', widget.properties),
),
],
],
),
),
const SizedBox(height: gap),
SizedBox(
height: timelineHeight,
child: _card('timeline', widget.timeline),
),
],
),
Positioned(
key: const Key('editor-timeline-divider'),
left: 0,
right: 0,
bottom: timelineHeight - WorkspaceLayoutMetrics.desktopResizeSlop,
height: WorkspaceLayoutMetrics.desktopResizeHitExtent,
child: WorkspaceResizeHandle(
key: const Key('editor-timeline-resize'),
axis: Axis.vertical,
initialValue: timelineHeight,
direction: -1,
onResize: (height) => widget.onTimelineHeightChanged(
height.clamp(minimum, maximum).toDouble(),
),
onEnd: widget.onTimelineHeightChangeEnd,
),
),
],
);
},
);
}