Files
cutdex/lib/features/properties/project_settings_dialog.dart
T
lingjhf 27e77fff39 feat: initial Cutdex application
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.
2026-10-05 23:36:23 +08:00

228 lines
7.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:cutdex/l10n/l10n.dart';
import 'package:cutdex_sdk/editor.dart';
import 'package:cutdex_sdk/runtime/contracts.dart';
import 'package:cutdex_sdk/timeline/model.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:cutdex_ui/theme.dart';
import '../../workspace/timeline_session.dart';
class ProjectSettingsDialog extends StatefulWidget {
const ProjectSettingsDialog({super.key, required this.session});
final EditorTimelineSession session;
@override
State<ProjectSettingsDialog> createState() => _ProjectSettingsDialogState();
}
class _ProjectSettingsDialogState extends State<ProjectSettingsDialog> {
static final _rates = <String, RationalTime>{
'23.976': RationalTime(1001, 24000),
'24': RationalTime(1, 24),
'25': RationalTime(1, 25),
'29.97': RationalTime(1001, 30000),
'30': RationalTime(1, 30),
'50': RationalTime(1, 50),
'59.94': RationalTime(1001, 60000),
'60': RationalTime(1, 60),
'120': RationalTime(1, 120),
};
static const _sizes = <String, (int, int)>{
'1920 × 1080': (1920, 1080),
'3840 × 2160': (3840, 2160),
'1280 × 720': (1280, 720),
'1080 × 1920': (1080, 1920),
'1080 × 1080': (1080, 1080),
};
final _form = GlobalKey<FormState>();
late final TextEditingController _width;
late final TextEditingController _height;
late RationalTime _frame;
late RenderColorSpace _color;
String? _preset;
@override
void initState() {
super.initState();
final canvas = widget.session.canvas;
_width = TextEditingController(text: canvas.width.toStringAsFixed(0));
_height = TextEditingController(text: canvas.height.toStringAsFixed(0));
_frame = widget.session.activeSequenceId == null
? TimelineFormat.fps24.frameDuration
: widget.session.persistence
.timeline(widget.session.activeSequenceId!)
.format
.frameDuration;
_color = widget.session.projectColorSpace;
_preset = _sizes.entries
.where((e) => e.value.$1 == canvas.width && e.value.$2 == canvas.height)
.firstOrNull
?.key;
}
@override
void dispose() {
_width.dispose();
_height.dispose();
super.dispose();
}
void _save() {
if (!_form.currentState!.validate()) return;
widget.session.setProjectProperties(
sequence: widget.session.activeSequenceId,
canvas: ProjectCanvas(
double.parse(_width.text),
double.parse(_height.text),
),
frameDuration: _frame,
colorSpace: _color,
);
Navigator.of(context).pop();
}
Widget _dimension(
TextEditingController controller,
String label,
String key,
) => FormField<String>(
initialValue: controller.text,
validator: (_) {
final value = int.tryParse(controller.text);
return value == null || !ProjectCanvas.isValidDimension(value.toDouble())
? context.l10n.projectResolutionInvalid
: null;
},
builder: (field) => AppTextField(
key: ValueKey(key),
controller: controller,
label: label,
errorText: field.errorText,
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
onChanged: (value) {
field.didChange(value);
setState(() => _preset = null);
},
),
);
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
final rates = {..._rates};
if (!rates.values.contains(_frame)) {
rates[(_frame.denominator / _frame.numerator).toStringAsFixed(3)] =
_frame;
}
return AppDialog(
title: l10n.projectSettings,
width: 440,
description: l10n.projectSettingsDescription,
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(l10n.cancel),
),
FilledButton(
key: const ValueKey('project-settings-save'),
onPressed: _save,
child: Text(l10n.save),
),
],
child: SingleChildScrollView(
child: Form(
key: _form,
child: AppFieldGroup(
children: [
AppField(
label: l10n.canvasSize,
child: AppFieldGroup(
children: [
AppSelect<String>(
emptyLabel: context.l10n.noMatchingOptions,
key: const ValueKey('project-resolution'),
value: _preset ?? 'custom',
label: l10n.canvasSize,
options: [
for (final name in _sizes.keys)
AppSelectOption(name, name),
AppSelectOption('custom', l10n.custom),
],
onChanged: (value) => setState(() {
_preset = value == 'custom' ? null : value;
final size = _sizes[value];
if (size != null) {
_width.text = '${size.$1}';
_height.text = '${size.$2}';
}
}),
),
Row(
spacing: AppSpacing.compact,
children: [
Expanded(
child: _dimension(
_width,
l10n.projectWidth,
'project-width',
),
),
Expanded(
child: _dimension(
_height,
l10n.projectHeight,
'project-height',
),
),
],
),
],
),
),
AppField(
label: l10n.frameRate,
child: AppSelect<RationalTime>(
emptyLabel: context.l10n.noMatchingOptions,
key: const ValueKey('project-frame-rate'),
value: _frame,
label: l10n.frameRate,
options: [
for (final rate in rates.entries)
AppSelectOption(rate.value, '${rate.key} fps'),
],
onChanged: (value) => setState(() => _frame = value),
),
),
AppField(
label: l10n.projectColorSpace,
child: AppSelect<RenderColorSpace>(
emptyLabel: context.l10n.noMatchingOptions,
key: const ValueKey('project-color-space'),
value: _color,
label: l10n.projectColorSpace,
options: const [
AppSelectOption(RenderColorSpace.rec709, 'SDR · Rec.709'),
AppSelectOption(
RenderColorSpace.rec2020HLG,
'HDR · Rec.2020 HLG',
),
AppSelectOption(
RenderColorSpace.rec2020PQ,
'HDR · Rec.2020 PQ',
),
],
onChanged: (value) => setState(() => _color = value),
),
),
],
),
),
),
);
}
}