Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
360 lines
15 KiB
Dart
360 lines
15 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cutdex/l10n/l10n.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../integrations/platform/device_experience.dart';
|
|
|
|
import 'package:cutdex_native/cutdex_native.dart';
|
|
|
|
import '../../persistence/app_settings_repositories.dart';
|
|
import '../../shared/layout/workspace_layout_metrics.dart';
|
|
|
|
import 'package:cutdex_ui/theme.dart';
|
|
|
|
import '../../workspace/timeline_provider.dart';
|
|
import '../../workspace/view_settings.dart';
|
|
import '../media/media_browser_page.dart';
|
|
import '../media/media_panel.dart';
|
|
import '../preview/preview_panel.dart';
|
|
import '../properties/properties_editor_page.dart';
|
|
import '../properties/properties_panel.dart';
|
|
import '../timeline/timeline_panel.dart';
|
|
import 'editor_presentation_controller.dart';
|
|
import 'layouts/bounded_editor_layout.dart';
|
|
import 'layouts/expanded_editor_layout.dart';
|
|
|
|
/// The single editing surface shown beside the project/timeline navigation.
|
|
class EditorWorkspace extends ConsumerStatefulWidget {
|
|
const EditorWorkspace({
|
|
super.key,
|
|
required this.projectId,
|
|
required this.timelineId,
|
|
required this.projectName,
|
|
required this.integratedTitlebar,
|
|
required this.headerLeading,
|
|
this.showProjectName = true,
|
|
this.experience = DeviceExperience.desktop,
|
|
});
|
|
|
|
final String projectId;
|
|
final String timelineId;
|
|
final String projectName;
|
|
final bool integratedTitlebar;
|
|
final Widget headerLeading;
|
|
final bool showProjectName;
|
|
final DeviceExperience experience;
|
|
|
|
@override
|
|
ConsumerState<EditorWorkspace> createState() => _EditorWorkspaceState();
|
|
}
|
|
|
|
class _EditorWorkspaceState extends ConsumerState<EditorWorkspace> {
|
|
final _previewKey = GlobalKey();
|
|
EditorPresentationController get _presentation =>
|
|
ref.read(editorPresentationProvider(widget.projectId));
|
|
ProjectViewSettingsData get _viewSettings =>
|
|
ref.read(projectViewSettingsProvider(widget.projectId)).value ??
|
|
const ProjectViewSettingsData();
|
|
ProjectViewSettings get _viewController =>
|
|
ref.read(projectViewSettingsProvider(widget.projectId).notifier);
|
|
bool get _propertiesOpen => _viewSettings.propertiesOpen;
|
|
double? get _timelineHeight => _viewSettings.timelineHeight;
|
|
|
|
void _saveViewSettings() {
|
|
if (!ref.read(projectViewSettingsProvider(widget.projectId)).hasValue) {
|
|
return;
|
|
}
|
|
unawaited(_viewController.save());
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final viewSettings = ref.watch(
|
|
projectViewSettingsProvider(widget.projectId),
|
|
);
|
|
final preview = KeyedSubtree(
|
|
key: _previewKey,
|
|
child: EditorPreviewPanel(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
),
|
|
);
|
|
final timeline = EditorTimelinePanel(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
);
|
|
final properties = EditorPropertiesPanel(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
);
|
|
final media = MediaPanel(projectId: widget.projectId);
|
|
return ListenableBuilder(
|
|
listenable: ref.watch(editorPresentationProvider(widget.projectId)),
|
|
builder: (context, _) => LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final desktop = widget.experience == DeviceExperience.desktop;
|
|
final sideWidth =
|
|
(_presentation.mediaOpen
|
|
? WorkspaceLayoutMetrics.mediaPanelWidth + 1
|
|
: 0) +
|
|
(_propertiesOpen
|
|
? WorkspaceLayoutMetrics.propertiesPanelWidth + 1
|
|
: 0);
|
|
final dockPanels =
|
|
desktop &&
|
|
constraints.maxWidth >=
|
|
WorkspaceLayoutMetrics.previewMinimumWidth + sideWidth;
|
|
final desktopTool = sideWidth == 0
|
|
? null
|
|
: _presentation.desktopTool(propertiesOpen: _propertiesOpen);
|
|
final headerHeight = desktop ? AppControlSize.panelHeader : 48.0;
|
|
final mediaOpen = desktop
|
|
? dockPanels
|
|
? _presentation.mediaOpen
|
|
: desktopTool == EditorTool.media
|
|
: _presentation.activeTool == EditorTool.media;
|
|
final propertiesOpen = desktop
|
|
? dockPanels
|
|
? _propertiesOpen
|
|
: desktopTool == EditorTool.properties
|
|
: _presentation.activeTool == EditorTool.properties;
|
|
Widget dockedEditing({required bool showTools}) =>
|
|
ExpandedEditorLayout(
|
|
preview: preview,
|
|
properties: properties,
|
|
media: media,
|
|
showMedia: showTools && _presentation.mediaOpen,
|
|
showProperties: showTools && _propertiesOpen,
|
|
timelineHeight: _timelineHeight,
|
|
onTimelineHeightChanged: (height) {
|
|
if (viewSettings.hasValue) {
|
|
_viewController.setTimelineHeight(height);
|
|
}
|
|
},
|
|
onTimelineHeightChangeEnd: _saveViewSettings,
|
|
timeline: timeline,
|
|
);
|
|
return Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
Column(
|
|
children: [
|
|
Material(
|
|
color: Theme.of(context).colorScheme.surface,
|
|
child: SizedBox(
|
|
key: const Key('editor-content-header'),
|
|
height: headerHeight,
|
|
child: WindowHeaderPadding(
|
|
child: Row(
|
|
children: [
|
|
widget.headerLeading,
|
|
Expanded(
|
|
child: widget.showProjectName
|
|
? Row(
|
|
children: [
|
|
Flexible(
|
|
fit: FlexFit.loose,
|
|
child: Text(
|
|
widget.projectName,
|
|
key: const Key(
|
|
'workspace-project-title',
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.titleSmall,
|
|
),
|
|
),
|
|
Flexible(
|
|
fit: FlexFit.loose,
|
|
child: _TimelineSaveStatus(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: const SizedBox.shrink(),
|
|
),
|
|
HeaderControlRegion(
|
|
child: SizedBox.square(
|
|
dimension: desktop
|
|
? AppControlSize.headerButton
|
|
: 48,
|
|
child: IconButton(
|
|
key: const Key('editor-media-button'),
|
|
tooltip: context.l10n.materials,
|
|
isSelected: mediaOpen,
|
|
onPressed: () {
|
|
if (desktop) {
|
|
if (!dockPanels &&
|
|
desktopTool != EditorTool.media &&
|
|
_presentation.mediaOpen) {
|
|
_presentation.preferDesktopTool(
|
|
EditorTool.media,
|
|
);
|
|
} else {
|
|
_presentation.toggleMedia();
|
|
}
|
|
} else {
|
|
_presentation.toggleTool(
|
|
EditorTool.media,
|
|
);
|
|
}
|
|
},
|
|
icon: const Icon(Icons.perm_media_outlined),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: AppSpacing.tiny),
|
|
HeaderControlRegion(
|
|
child: SizedBox.square(
|
|
dimension: desktop
|
|
? AppControlSize.headerButton
|
|
: 48,
|
|
child: IconButton(
|
|
key: const Key('editor-properties-button'),
|
|
tooltip: propertiesOpen
|
|
? context.l10n.collapseProperties
|
|
: context.l10n.expandProperties,
|
|
isSelected: propertiesOpen,
|
|
onPressed: !viewSettings.hasValue
|
|
? null
|
|
: () {
|
|
if (desktop) {
|
|
if (dockPanels ||
|
|
desktopTool ==
|
|
EditorTool.properties ||
|
|
!_propertiesOpen) {
|
|
_viewController.setPropertiesOpen(
|
|
!_propertiesOpen,
|
|
);
|
|
_saveViewSettings();
|
|
}
|
|
_presentation.preferDesktopTool(
|
|
EditorTool.properties,
|
|
);
|
|
} else {
|
|
_presentation.toggleTool(
|
|
EditorTool.properties,
|
|
);
|
|
}
|
|
},
|
|
icon: const Icon(
|
|
Icons.tune,
|
|
size: AppIconSize.header,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: AppSpacing.compact),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: dockPanels
|
|
? dockedEditing(showTools: true)
|
|
: BoundedEditorLayout(
|
|
experience: widget.experience,
|
|
editing: desktop
|
|
? dockedEditing(showTools: false)
|
|
: TouchEditingLayout(
|
|
preview: preview,
|
|
timeline: timeline,
|
|
),
|
|
tool: desktop
|
|
? desktopTool
|
|
: _presentation.activeTool,
|
|
media: switch (widget.experience) {
|
|
DeviceExperience.desktop => media,
|
|
DeviceExperience.tablet => MediaBrowserDrawer(
|
|
projectId: widget.projectId,
|
|
),
|
|
DeviceExperience.phone => MediaBrowserPage(
|
|
projectId: widget.projectId,
|
|
),
|
|
},
|
|
properties: switch (widget.experience) {
|
|
DeviceExperience.desktop => properties,
|
|
DeviceExperience.tablet => PropertiesToolPanel(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
),
|
|
DeviceExperience.phone => PropertiesEditorPage(
|
|
projectId: widget.projectId,
|
|
timelineId: widget.timelineId,
|
|
),
|
|
},
|
|
onCloseTool: () {
|
|
if (!desktop) {
|
|
_presentation.closeTool();
|
|
} else if (desktopTool == EditorTool.media) {
|
|
_presentation.toggleMedia();
|
|
} else {
|
|
_viewController.setPropertiesOpen(false);
|
|
_saveViewSettings();
|
|
}
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Positioned(
|
|
key: const Key('editing-top-divider'),
|
|
top: headerHeight,
|
|
left: 0,
|
|
right: 0,
|
|
height: 1,
|
|
child: const Divider(height: 1),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _TimelineSaveStatus extends ConsumerWidget {
|
|
const _TimelineSaveStatus({
|
|
required this.projectId,
|
|
required this.timelineId,
|
|
});
|
|
|
|
final String projectId;
|
|
final String timelineId;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final session = ref
|
|
.watch(editorTimelineProvider(projectId, timelineId))
|
|
.asData
|
|
?.value;
|
|
if (session == null) return const SizedBox.shrink();
|
|
return ListenableBuilder(
|
|
listenable: session,
|
|
builder: (context, _) => Padding(
|
|
padding: const EdgeInsets.only(left: AppSpacing.small),
|
|
child: Text(
|
|
session.error != null
|
|
? context.l10n.unsaved
|
|
: session.saving
|
|
? context.l10n.saving
|
|
: session.dirty
|
|
? context.l10n.pendingSave
|
|
: context.l10n.saved,
|
|
key: const Key('timeline-save-status'),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(fontSize: 10),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|