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.
90 lines
3.2 KiB
Dart
90 lines
3.2 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../integrations/platform/file_picker.dart';
|
|
import '../../integrations/platform/platform_capabilities.dart';
|
|
import '../../workspace/media_file_extensions.dart';
|
|
import '../../workspace/external_media_import.dart';
|
|
import '../../workspace/projects.dart';
|
|
import 'agent_composer_controller.dart';
|
|
import 'agent_media_attachments.dart';
|
|
import 'composer_document.dart';
|
|
|
|
/// Composition survives presentation changes, including temporarily hidden chat.
|
|
final agentComposerStoreProvider = Provider<AgentComposerStore>((ref) {
|
|
final store = AgentComposerStore(
|
|
createComposer: (projectId) => AgentComposerController(
|
|
canImport: () =>
|
|
ref.mounted &&
|
|
projectId != null &&
|
|
ref.read(platformCapabilitiesProvider).localFileSelection &&
|
|
ref.read(projectsProvider).value?.activeProject?.id == projectId &&
|
|
ref.read(projectsProvider).value?.projectBusy == false &&
|
|
!ref.read(externalMediaImportProvider(projectId)).isLoading,
|
|
pickFiles: () => ref
|
|
.read(filePickerProvider)
|
|
.pickFiles(allowedExtensions: selectableMediaFileExtensions),
|
|
importMedia: (files) => ref
|
|
.read(externalMediaImportProvider(projectId!).notifier)
|
|
.importFiles(files),
|
|
),
|
|
);
|
|
ref.onDispose(store.dispose);
|
|
return store;
|
|
});
|
|
|
|
final class AgentComposerStore {
|
|
AgentComposerStore({required this.createComposer});
|
|
final AgentComposerController Function(String?) createComposer;
|
|
ComposerDocumentController _draft = ComposerDocumentController();
|
|
ComposerDocumentController get draft => _draft;
|
|
final _inputs = <(String?, String), ComposerDocumentController>{};
|
|
final _composers = <(String?, String), AgentComposerController>{};
|
|
|
|
ComposerDocumentController input(String? projectId, String? conversationId) =>
|
|
conversationId == null
|
|
? draft
|
|
: _inputs.putIfAbsent((
|
|
projectId,
|
|
conversationId,
|
|
), ComposerDocumentController.new);
|
|
|
|
List<AgentMediaAttachment> attachments(String? projectId, String key) =>
|
|
composer(projectId, key).attachments;
|
|
|
|
AgentComposerController composer(String? projectId, String key) =>
|
|
_composers.putIfAbsent((projectId, key), () => createComposer(projectId));
|
|
|
|
void promoteDraft(String projectId, String draftKey, String conversationId) {
|
|
final destination = (projectId, conversationId);
|
|
_inputs.remove(destination)?.dispose();
|
|
_inputs[destination] = _draft;
|
|
_draft = ComposerDocumentController();
|
|
final composer = _composers.remove((projectId, draftKey));
|
|
if (composer != null) {
|
|
_composers.remove(destination)?.dispose();
|
|
_composers[destination] = composer;
|
|
}
|
|
}
|
|
|
|
void removeConversation(String projectId, String conversationId) {
|
|
_inputs.remove((projectId, conversationId))?.dispose();
|
|
_composers.remove((projectId, conversationId))?.dispose();
|
|
}
|
|
|
|
void removeDraft(String? projectId, String draftKey) {
|
|
_composers.remove((projectId, draftKey))?.dispose();
|
|
}
|
|
|
|
void dispose() {
|
|
draft.dispose();
|
|
for (final input in _inputs.values) {
|
|
input.dispose();
|
|
}
|
|
_inputs.clear();
|
|
for (final composer in _composers.values) {
|
|
composer.dispose();
|
|
}
|
|
_composers.clear();
|
|
}
|
|
}
|