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 onTimelineHeightChanged; final VoidCallback onTimelineHeightChangeEnd; final Widget timeline; @override State createState() => _ExpandedEditorLayoutState(); } class _ExpandedEditorLayoutState extends State { 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, ), ), ], ); }, ); }