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

+276
View File
@@ -0,0 +1,276 @@
import 'package:cutdex/integrations/platform/native_project_drop_region.dart';
import 'package:cutdex/integrations/platform/native_file_drop_policy.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const manager = MethodChannel('cutdex_native/file_drop');
setUp(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(manager, (_) async => null);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(manager, null);
});
for (final name in [
'cutdex_native/file_drop/media-library',
'cutdex_native/file_drop/attachments',
]) {
testWidgets('$name receives events after replacement', (tester) async {
final channel = MethodChannel(name);
final messenger = tester.binding.defaultBinaryMessenger;
messenger.setMockMethodCallHandler(channel, (_) async => null);
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
var entered = 0;
Widget target(String key) => MaterialApp(
home: NativeProjectDropRegion(
key: ValueKey(key),
regionId: name.split('/').last,
policy: name == 'cutdex_native/file_drop/attachments'
? NativeFileDropPolicy.attachments
: NativeFileDropPolicy.mediaLibrary,
enabled: true,
onEnter: (_) => entered++,
onExit: () {},
onDrop: (_) async {},
child: const SizedBox.expand(),
),
);
await tester.pumpWidget(target('old'));
await tester.pumpAndSettle();
await tester.pumpWidget(target('new'));
await tester.pumpAndSettle();
await messenger.handlePlatformMessage(
name,
const StandardMethodCodec().encodeMethodCall(
const MethodCall('event', {
'phase': 'enter',
'session': 1,
'files': [
{'path': '/sample.mp4'},
],
}),
),
(_) {},
);
await tester.pump();
expect(entered, 1);
await tester.pumpWidget(const SizedBox());
await tester.pumpAndSettle();
});
}
testWidgets('policy changes at fixed bounds update native acceptance', (
tester,
) async {
const channel = MethodChannel('cutdex_native/file_drop/media-library');
final messenger = tester.binding.defaultBinaryMessenger;
final calls = <MethodCall>[];
messenger.setMockMethodCallHandler(channel, (call) async {
calls.add(call);
return null;
});
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
Widget target(NativeFileDropPolicy policy) => MaterialApp(
home: NativeProjectDropRegion(
policy: policy,
enabled: true,
onEnter: (_) {},
onExit: () {},
onDrop: (_) async {},
child: const SizedBox.expand(),
),
);
await tester.pumpWidget(target(NativeFileDropPolicy.mediaLibrary));
await tester.pumpAndSettle();
final library = calls.last.arguments as Map;
// The importer handles failures per file, preserving valid mixed batches.
expect(library['allowedExtensions'], isNull);
calls.clear();
await tester.pumpWidget(target(NativeFileDropPolicy.timeline));
await tester.pumpAndSettle();
final timeline = calls.single.arguments as Map;
expect(timeline['width'], library['width']);
expect(timeline['allowedExtensions'], contains('wav'));
expect(timeline['allowedExtensions'], isNot(contains('png')));
expect(timeline['maximumFileCount'], 1);
calls.clear();
await tester.pumpWidget(target(NativeFileDropPolicy.attachments));
await tester.pumpAndSettle();
final attachments = calls.single.arguments as Map;
expect(attachments['allowedExtensions'], isNull);
expect(attachments['maximumFileCount'], isNull);
await tester.pumpWidget(const SizedBox());
await tester.pumpAndSettle();
});
testWidgets(
'timeline rejects images and batches while attachments accept documents',
(tester) async {
const name = 'cutdex_native/file_drop/media-library';
const channel = MethodChannel(name);
final messenger = tester.binding.defaultBinaryMessenger;
final released = <int>[];
messenger.setMockMethodCallHandler(channel, (call) async {
if (call.method == 'release') {
released.add((call.arguments as Map)['session'] as int);
}
return null;
});
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
var entered = 0, dropped = 0, exited = 0;
Widget target(NativeFileDropPolicy policy) => MaterialApp(
home: NativeProjectDropRegion(
policy: policy,
enabled: true,
onEnter: (_) => entered++,
onExit: () => exited++,
onDrop: (_) async {
dropped++;
},
child: const SizedBox.expand(),
),
);
Future<void> event(String phase, int id, List<String> paths) async {
await messenger.handlePlatformMessage(
name,
const StandardMethodCodec().encodeMethodCall(
MethodCall('event', {
'phase': phase,
'session': id,
'files': [
for (final path in paths) {'path': path},
],
}),
),
(_) {},
);
await tester.pump();
}
await tester.pumpWidget(target(NativeFileDropPolicy.timeline));
await tester.pumpAndSettle();
await event('enter', 1, ['/image.png']);
await event('enter', 2, ['/a.wav', '/b.mov']);
expect(entered, 0);
expect(released, [1, 2]);
await event('enter', 3, ['/a.WAV']);
await event('drop', 3, ['/a.WAV']);
expect(entered, 1);
expect(dropped, 1);
// A changed drop payload must not commit now-rejected paths.
await event('enter', 4, ['/a.wav']);
await event('drop', 4, ['/image.png']);
expect(dropped, 1);
expect(exited, 1);
expect(released, [1, 2, 3, 4]);
await tester.pumpWidget(target(NativeFileDropPolicy.attachments));
await tester.pumpAndSettle();
await event('enter', 5, ['/notes.pdf', '/README']);
await event('drop', 5, ['/notes.pdf', '/README']);
expect(entered, 3);
expect(dropped, 2);
expect(released, [1, 2, 3, 4, 5]);
await tester.pumpWidget(target(NativeFileDropPolicy.timeline));
await tester.pumpAndSettle();
await event('enter', 6, ['/素材/transport stream.TS']);
await event('drop', 6, ['/素材/transport stream.TS']);
expect(entered, 4);
expect(dropped, 3);
expect(released, [1, 2, 3, 4, 5, 6]);
await tester.pumpWidget(const SizedBox());
await tester.pumpAndSettle();
},
);
testWidgets('disabled drop region activates without a geometry change', (
tester,
) async {
const channel = MethodChannel('cutdex_native/file_drop/media-library');
final messenger = tester.binding.defaultBinaryMessenger;
final calls = <MethodCall>[];
messenger.setMockMethodCallHandler(channel, (call) async {
calls.add(call);
return null;
});
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
final enabled = ValueNotifier(false);
addTearDown(enabled.dispose);
await tester.pumpWidget(
MaterialApp(
home: ValueListenableBuilder<bool>(
valueListenable: enabled,
child: const SizedBox.expand(),
builder: (_, value, child) => NativeProjectDropRegion(
enabled: value,
onEnter: (_) {},
onExit: () {},
onDrop: (_) async {},
child: child!,
),
),
),
);
await tester.pumpAndSettle();
calls.clear();
enabled.value = true;
await tester.pumpAndSettle();
expect(
calls.where((c) => c.method == 'setRegion' && c.arguments != null),
isNotEmpty,
);
calls.clear();
enabled.value = false;
await tester.pumpAndSettle();
expect(calls.last.arguments, isNull);
calls.clear();
enabled.value = true;
await tester.pumpAndSettle();
expect(calls.single.arguments, isNotNull);
await tester.pumpWidget(const SizedBox());
await tester.pumpAndSettle();
expect(calls.last.arguments, isNull);
});
testWidgets('TickerMode restores the drop region without changing layout', (
tester,
) async {
const channel = MethodChannel('cutdex_native/file_drop/media-library');
final messenger = tester.binding.defaultBinaryMessenger;
final calls = <MethodCall>[];
messenger.setMockMethodCallHandler(channel, (call) async {
calls.add(call);
return null;
});
addTearDown(() => messenger.setMockMethodCallHandler(channel, null));
final active = ValueNotifier(false);
addTearDown(active.dispose);
await tester.pumpWidget(
MaterialApp(
home: ValueListenableBuilder<bool>(
valueListenable: active,
child: NativeProjectDropRegion(
enabled: true,
onEnter: (_) {},
onExit: () {},
onDrop: (_) async {},
child: const SizedBox.expand(),
),
builder: (_, value, child) =>
TickerMode(enabled: value, child: child!),
),
),
);
await tester.pumpAndSettle();
for (final value in [true, false, true]) {
calls.clear();
active.value = value;
await tester.pumpAndSettle();
final region = calls
.lastWhere((call) => call.method == 'setRegion')
.arguments;
expect(region, value ? isNotNull : isNull);
}
await tester.pumpWidget(const SizedBox());
await tester.pumpAndSettle();
});
}