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.
240 lines
7.9 KiB
Dart
240 lines
7.9 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cutdex_sdk/timeline/model.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../l10n/l10n.dart';
|
|
|
|
import 'package:cutdex_ui/theme.dart';
|
|
|
|
class FullscreenPlaybackBar extends StatefulWidget {
|
|
const FullscreenPlaybackBar({
|
|
super.key,
|
|
required this.positionTick,
|
|
required this.durationTick,
|
|
required this.frameTick,
|
|
required this.playing,
|
|
required this.onPlayPause,
|
|
required this.onSeek,
|
|
required this.onExit,
|
|
required this.onScrubStart,
|
|
required this.onScrubUpdate,
|
|
required this.onScrubEnd,
|
|
});
|
|
|
|
final int positionTick;
|
|
final int durationTick;
|
|
final int frameTick;
|
|
final bool playing;
|
|
final VoidCallback? onPlayPause;
|
|
final ValueChanged<int>? onSeek;
|
|
final VoidCallback? onExit;
|
|
final VoidCallback? onScrubStart;
|
|
final ValueChanged<int>? onScrubUpdate;
|
|
final ValueChanged<int>? onScrubEnd;
|
|
|
|
@override
|
|
State<FullscreenPlaybackBar> createState() => _FullscreenPlaybackBarState();
|
|
}
|
|
|
|
class _FullscreenPlaybackBarState extends State<FullscreenPlaybackBar> {
|
|
double? _dragPosition;
|
|
|
|
int get _position => (_dragPosition?.round() ?? widget.positionTick).clamp(
|
|
0,
|
|
widget.durationTick,
|
|
);
|
|
|
|
void _step(int direction) {
|
|
final tick = (_position ~/ widget.frameTick + direction) * widget.frameTick;
|
|
widget.onSeek?.call(tick.clamp(0, widget.durationTick));
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
if (_dragPosition case final value?) {
|
|
final end = widget.onScrubEnd;
|
|
scheduleMicrotask(() => end?.call(value.round()));
|
|
}
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final enabled = widget.onSeek != null && widget.durationTick > 0;
|
|
final colors = Theme.of(context).colorScheme;
|
|
return SizedBox(
|
|
key: const Key('fullscreen-playback-bar'),
|
|
height: 76,
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(
|
|
AppSpacing.compact,
|
|
AppSpacing.tiny,
|
|
AppSpacing.compact,
|
|
AppSpacing.small,
|
|
),
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
height: 36,
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: _button(
|
|
context,
|
|
Icons.first_page,
|
|
context.l10n.previewGoToStart,
|
|
enabled ? () => widget.onSeek!(0) : null,
|
|
),
|
|
),
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
_button(
|
|
context,
|
|
Icons.skip_previous,
|
|
context.l10n.previewPreviousFrame,
|
|
enabled && _position > 0 ? () => _step(-1) : null,
|
|
),
|
|
_button(
|
|
context,
|
|
widget.playing ? Icons.pause : Icons.play_arrow,
|
|
widget.playing ? context.l10n.pause : context.l10n.play,
|
|
widget.onPlayPause,
|
|
size: 32,
|
|
),
|
|
_button(
|
|
context,
|
|
Icons.skip_next,
|
|
context.l10n.previewNextFrame,
|
|
enabled && _position < widget.durationTick
|
|
? () => _step(1)
|
|
: null,
|
|
),
|
|
],
|
|
),
|
|
Align(
|
|
alignment: Alignment.centerRight,
|
|
child: _button(
|
|
context,
|
|
Icons.fullscreen_exit,
|
|
context.l10n.exitPreviewFullscreen,
|
|
widget.onExit,
|
|
key: const Key('preview-fullscreen'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Row(
|
|
children: [
|
|
_timeLabel(context, _time(_position)),
|
|
Expanded(
|
|
child: SliderTheme(
|
|
data: SliderTheme.of(context).copyWith(
|
|
trackHeight: 4,
|
|
activeTrackColor: colors.outline,
|
|
inactiveTrackColor: colors.surfaceContainerHighest,
|
|
thumbColor: colors.onSurface,
|
|
overlayColor: colors.onSurface.withValues(alpha: .12),
|
|
thumbShape: const RoundSliderThumbShape(
|
|
enabledThumbRadius: 5,
|
|
disabledThumbRadius: 5,
|
|
elevation: 0,
|
|
pressedElevation: 0,
|
|
),
|
|
overlayShape: const RoundSliderOverlayShape(
|
|
overlayRadius: 10,
|
|
),
|
|
trackShape: const RoundedRectSliderTrackShape(),
|
|
),
|
|
child: Slider(
|
|
key: const Key('fullscreen-progress'),
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: AppSpacing.small,
|
|
),
|
|
value: _position.toDouble(),
|
|
max: widget.durationTick > 0
|
|
? widget.durationTick.toDouble()
|
|
: 1,
|
|
onChangeStart: enabled
|
|
? (value) {
|
|
setState(() => _dragPosition = value);
|
|
widget.onScrubStart?.call();
|
|
}
|
|
: null,
|
|
onChanged: enabled
|
|
? (value) {
|
|
setState(() => _dragPosition = value);
|
|
widget.onScrubUpdate?.call(value.round());
|
|
}
|
|
: null,
|
|
onChangeEnd: enabled
|
|
? (value) {
|
|
setState(() => _dragPosition = null);
|
|
widget.onScrubEnd?.call(value.round());
|
|
}
|
|
: null,
|
|
),
|
|
),
|
|
),
|
|
_timeLabel(
|
|
context,
|
|
'-${_time(widget.durationTick - _position)}',
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _button(
|
|
BuildContext context,
|
|
IconData icon,
|
|
String tooltip,
|
|
VoidCallback? onPressed, {
|
|
double size = 20,
|
|
Key? key,
|
|
}) {
|
|
final colors = Theme.of(context).colorScheme;
|
|
return IconButton(
|
|
key: key,
|
|
tooltip: tooltip,
|
|
onPressed: onPressed,
|
|
padding: EdgeInsets.zero,
|
|
constraints: const BoxConstraints.tightFor(width: 36, height: 36),
|
|
visualDensity: VisualDensity.compact,
|
|
color: colors.onSurface,
|
|
disabledColor: colors.onSurface.withValues(alpha: .38),
|
|
icon: Icon(icon, size: size),
|
|
);
|
|
}
|
|
|
|
Widget _timeLabel(BuildContext context, String value) => SizedBox(
|
|
width: 62,
|
|
child: Text(
|
|
value,
|
|
textAlign: TextAlign.center,
|
|
maxLines: 1,
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
fontFeatures: [const FontFeature.tabularFigures()],
|
|
),
|
|
),
|
|
);
|
|
|
|
String _time(int tick) {
|
|
final seconds = tick ~/ TimelineClock.ticksPerSecond;
|
|
final minutes = seconds ~/ 60;
|
|
final tail = '${seconds % 60}'.padLeft(2, '0');
|
|
if (minutes < 60) return '${minutes.toString().padLeft(2, '0')}:$tail';
|
|
return '${minutes ~/ 60}:${(minutes % 60).toString().padLeft(2, '0')}:$tail';
|
|
}
|
|
}
|