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.
This commit is contained in:
lingjhf committed 2026-10-05 23:36:23 +08:00
commit 27e77fff39
718 files changed
+183958

No files matched your search

@@ -0,0 +1,579 @@
import 'dart:async';
import 'package:cutdex/l10n/l10n.dart';
import 'dart:math' as math;
import 'package:cutdex/features/properties/animation_labels.dart';
import 'package:cutdex_sdk/editor.dart';
import 'package:cutdex_sdk/preview.dart';
import 'package:cutdex_sdk/timeline/model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import '../preview/preview_panel.dart';
import 'property_number_input.dart';
class MaskProperties extends ConsumerStatefulWidget {
const MaskProperties({
super.key,
required this.projectId,
required this.timelineId,
required this.element,
});
final String projectId, timelineId;
final ElementId element;
@override
ConsumerState<MaskProperties> createState() => _MaskPropertiesState();
}
class _MaskPropertiesState extends ConsumerState<MaskProperties> {
PreviewController? _preview;
ElementId? _boundElement;
String? _error;
int? _gestureGeneration;
String? _scrubField;
ClipMask Function(double)? _scrubChange;
double _scrubValue = 0;
Future<bool>? _pendingValueCommit;
@override
void dispose() {
final preview = _preview;
scheduleMicrotask(() => preview?.releaseMaskEditing(this));
super.dispose();
}
bool _apply(PreviewController preview, ClipMask mask) {
try {
preview.applyMask(mask);
setState(() => _error = null);
return true;
} catch (_) {
setState(() => _error = context.l10n.updateMaskFailed);
return false;
}
}
Future<bool> _submitValue(
PreviewController preview,
double value,
double min,
double max,
ClipMask Function(double) change,
) {
final operation = Future<bool>.sync(
() =>
value.isFinite &&
value >= min &&
value <= max &&
_apply(preview, change(value)),
);
_pendingValueCommit = operation;
return operation.whenComplete(() {
if (identical(_pendingValueCommit, operation)) _pendingValueCommit = null;
});
}
Future<void> _editKeys(PreviewController preview, List<String> ids) async {
final element = widget.element;
final maskId = preview.selectedMaskId;
final tick = preview.positionTick;
FocusManager.instance.primaryFocus?.unfocus();
FocusManager.instance.applyFocusChangesIfNeeded();
final pending = _pendingValueCommit;
if (pending != null && !await pending) return;
if (!mounted ||
widget.element != element ||
_preview != preview ||
preview.maskEditingElement != element ||
preview.selectedMaskId != maskId ||
preview.positionTick != tick ||
_scrubField != null) {
return;
}
try {
preview.toggleMaskKeys(ids);
} catch (_) {
setState(() => _error = context.l10n.updateKeyframesFailed);
}
}
@override
Widget build(BuildContext context) {
final preview = ref
.watch(editorPreviewProvider(widget.projectId, widget.timelineId))
.value;
if (preview == null) return const SizedBox.shrink();
if (_preview != preview || _boundElement != widget.element) {
final previous = _preview;
if (previous != null && previous != preview) {
scheduleMicrotask(() => previous.releaseMaskEditing(this));
}
_preview = preview;
_boundElement = widget.element;
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted && identical(_preview, preview)) {
preview.setMaskEditing(widget.element, owner: this);
}
});
}
return ListenableBuilder(
listenable: preview,
builder: (context, _) {
final mask = preview.maskFor(widget.element);
final animation = preview.maskAnimation(widget.element);
final stack = preview.maskStackFor(widget.element);
final layers =
preview.maskStackFor(widget.element)?.layers ?? <ClipMaskLayer>[];
final selectedId = preview.selectedMaskId;
final initialId = layers.where((e) => e.enabled).firstOrNull?.id;
final enabled =
preview.canPlay &&
stack != null &&
preview.maskEditingElement == widget.element;
Widget key(String label) {
final ids = localizedMaskChannels(context)[label]!;
return IconButton(
key: ValueKey('mask-key-$label'),
tooltip: context.l10n.keyframeLabel(label),
isSelected: animation?.keyed(ids) == true,
onPressed: enabled && _scrubField == null && animation != null
? () => _editKeys(preview, ids)
: null,
icon: Transform.rotate(
angle: math.pi / 4,
child: Icon(
animation?.keyed(ids) == true
? Icons.square
: Icons.crop_square,
size: 12,
color: animation?.keyed(ids) == true
? Theme.of(context).colorScheme.primary
: null,
),
),
);
}
Widget field(
String label,
double value,
double min,
double max,
ClipMask Function(double) change, {
String? unit,
bool wrapRotation = false,
}) => PropertyNumberInput(
key: ValueKey((selectedId, label)),
label: label,
unit: unit,
value: value,
enabled: enabled,
readOnly: _scrubField != null,
scrubbing: _scrubField == label,
editContext: (
widget.element,
selectedId,
stack?.record,
stack?.localTick,
),
submit: (v) => _submitValue(preview, v, min, max, change),
onScrubStart: () {
if (_scrubField != null) return false;
final preparing = preview.beginMaskEdit();
final generation = _gestureGeneration = preview.maskEditGeneration;
_scrubChange = change;
_scrubValue = value;
setState(() => _scrubField = label);
unawaited(
preparing
.then((ready) {
if (!ready && generation == preview.maskEditGeneration) {
preview.cancelMaskEdit();
if (mounted) setState(() => _scrubField = null);
}
})
.catchError((Object error) {
if (generation == preview.maskEditGeneration) {
preview.cancelMaskEdit();
if (mounted) {
setState(() {
_scrubField = null;
_error = context.l10n.maskPreviewFailed;
});
}
}
}),
);
return true;
},
onScrubUpdate: (distance) {
if (_gestureGeneration == preview.maskEditGeneration) {
preview.updateMask(
_scrubChange!(
wrapRotation
? normalizeRotationDegrees(_scrubValue + distance)
: (_scrubValue + distance).clamp(min, max),
),
);
}
},
onScrubEnd: () {
if (_gestureGeneration == preview.maskEditGeneration) {
preview.endMaskEdit();
}
if (mounted) setState(() => _scrubField = null);
},
onScrubCancel: () {
if (_gestureGeneration == preview.maskEditGeneration) {
preview.cancelMaskEdit();
}
if (mounted) setState(() => _scrubField = null);
},
);
Widget axes(String label, Widget first, Widget second) => LayoutBuilder(
builder: (context, constraints) => Row(
children: [
Expanded(
child: constraints.maxWidth < 240
? Column(
children: [
first,
const SizedBox(height: AppSpacing.small),
second,
],
)
: Row(
children: [
Expanded(child: first),
const SizedBox(width: AppSpacing.small),
Expanded(child: second),
],
),
),
const SizedBox(width: AppSpacing.small),
key(label),
],
),
);
Widget singleField(String label, Widget input) => Row(
children: [
Expanded(child: input),
const SizedBox(width: AppSpacing.small),
key(label),
],
);
Widget heading(String label) => Padding(
padding: const EdgeInsets.only(bottom: AppSpacing.small),
child: Text(
label,
style: AppTheme.propertySectionTitleStyle(context),
),
);
Widget section(List<Widget> children) => Padding(
padding: AppSpacing.panelSection,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: children,
),
);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
section([
Row(
children: [
Expanded(
child: Text(
context.l10n.mask,
style: AppTheme.propertySectionTitleStyle(context),
),
),
IconButton(
tooltip: context.l10n.moveMaskUp,
icon: const Icon(Icons.arrow_upward, size: 18),
onPressed:
enabled &&
layers.indexWhere((e) => e.id == selectedId) > 0
? () {
final ids = layers.map((e) => e.id).toList();
final i = ids.indexOf(selectedId!);
ids.insert(i - 1, ids.removeAt(i));
preview.reorderMasks(ids);
}
: null,
),
IconButton(
tooltip: context.l10n.moveMaskDown,
icon: const Icon(Icons.arrow_downward, size: 18),
onPressed:
enabled &&
selectedId != null &&
layers.lastOrNull?.id != selectedId
? () {
final ids = layers.map((e) => e.id).toList();
final i = ids.indexOf(selectedId);
ids.insert(i + 1, ids.removeAt(i));
preview.reorderMasks(ids);
}
: null,
),
AppDropdownMenu(
enabled: enabled,
items: [
AppMenuItem(
label: context.l10n.rectangle,
onPressed: () =>
preview.addMask(ClipMaskShape.rectangle),
),
AppMenuItem(
label: context.l10n.ellipse,
onPressed: () => preview.addMask(ClipMaskShape.ellipse),
),
],
builder: (context, toggle, focusNode) => IconButton(
focusNode: focusNode,
tooltip: context.l10n.addMask,
icon: const Icon(Icons.add),
onPressed: toggle,
),
),
],
),
]),
section([
AppItemGroup(
children: [
for (var i = 0; i < layers.length; i++)
AppItem(
key: ValueKey('mask-row-${layers[i].id}'),
selected: layers[i].id == selectedId,
onPressed: () => preview.selectMask(layers[i].id),
leading: IconButton(
tooltip: layers[i].enabled
? context.l10n.disableMask
: context.l10n.enableMask,
icon: Icon(
layers[i].enabled
? Icons.visibility_outlined
: Icons.visibility_off_outlined,
size: 18,
),
onPressed: enabled
? () => preview.configureMask(
layers[i].id,
enabled: !layers[i].enabled,
)
: null,
),
actions: [
AppDropdownMenu(
enabled: enabled && layers[i].id != initialId,
items: [
for (final mode in ClipMaskMode.values)
AppMenuItem(
label: [
context.l10n.add,
context.l10n.intersect,
context.l10n.subtract,
][mode.index],
selected: layers[i].mode == mode,
onPressed: () => preview.configureMask(
layers[i].id,
mode: mode,
),
),
],
builder: (context, toggle, focusNode) => IconButton(
focusNode: focusNode,
tooltip: layers[i].id == initialId
? context.l10n.initialRegion
: context.l10n.maskMode(
[
context.l10n.add,
context.l10n.intersect,
context.l10n.subtract,
][layers[i].mode.index],
),
icon: Icon(
layers[i].id == initialId
? Icons.crop_free
: switch (layers[i].mode) {
ClipMaskMode.add => Icons.add,
ClipMaskMode.intersect =>
Icons.filter_center_focus,
ClipMaskMode.subtract => Icons.remove,
},
size: AppIconSize.standard,
),
onPressed: toggle,
),
),
IconButton(
tooltip: context.l10n.deleteMask,
icon: const Icon(Icons.delete_outline, size: 18),
onPressed: enabled
? () => preview.removeMask(layers[i].id)
: null,
),
],
child: Text(
'${[context.l10n.rectangle, context.l10n.ellipse][layers[i].mask.shape.index]} ${i + 1}',
),
),
],
),
]),
if (mask != null && animation != null) ...[
section([
Row(
children: [
Expanded(
child: AppButtonGroup(
expanded: true,
label: context.l10n.mask,
children: [
for (final entry in [
(
ClipMaskShape.rectangle,
Icons.crop_square,
context.l10n.rectangle,
),
(
ClipMaskShape.ellipse,
Icons.circle_outlined,
context.l10n.ellipse,
),
])
IconButton(
key: ValueKey('mask-shape-${entry.$1.name}'),
tooltip: entry.$3,
isSelected: mask.shape == entry.$1,
onPressed: enabled
? () => _apply(
preview,
mask.copyWith(shape: entry.$1),
)
: null,
icon: Icon(entry.$2),
),
],
),
),
const SizedBox(width: AppSpacing.small),
IconButton(
tooltip: context.l10n.resetMask,
onPressed: enabled
? () => _apply(preview, ClipMask(shape: mask.shape))
: null,
icon: const Icon(Icons.restart_alt),
),
],
),
]),
section([
heading(context.l10n.position),
axes(
context.l10n.position,
field(
'X',
mask.x * 100,
ClipMask.minPosition * 100,
ClipMask.maxPosition * 100,
(v) => mask.copyWith(x: v / 100),
unit: '%',
),
field(
'Y',
mask.y * 100,
ClipMask.minPosition * 100,
ClipMask.maxPosition * 100,
(v) => mask.copyWith(y: v / 100),
unit: '%',
),
),
]),
section([
singleField(
context.l10n.rotation,
field(
context.l10n.rotation,
mask.rotation,
-180,
180,
(v) => mask.copyWith(rotation: v),
unit: '°',
wrapRotation: true,
),
),
]),
section([
heading(context.l10n.size),
axes(
context.l10n.size,
field(
'W',
mask.width * 100,
ClipMask.minExtent * 100,
ClipMask.maxExtent * 100,
(v) => mask.copyWith(width: v / 100),
unit: '%',
),
field(
'H',
mask.height * 100,
ClipMask.minExtent * 100,
ClipMask.maxExtent * 100,
(v) => mask.copyWith(height: v / 100),
unit: '%',
),
),
]),
section([
singleField(
context.l10n.feather,
field(
context.l10n.feather,
mask.feather * 100,
0,
100,
(v) => mask.copyWith(feather: v / 100),
unit: '%',
),
),
]),
section([
Row(
children: [
Expanded(
child: Text(
context.l10n.invert,
style: AppTheme.propertySectionTitleStyle(context),
),
),
AppSwitch(
value: mask.inverted,
onChanged: enabled
? (v) => _apply(preview, mask.copyWith(inverted: v))
: null,
),
],
),
]),
],
if (_error != null)
section([
Text(
_error!,
style: TextStyle(color: Theme.of(context).colorScheme.error),
),
]),
],
);
},
);
}
}