Files
cutdex/lib/features/preview/fullscreen_playback_bar.dart
lingjhf 06f1c26681
Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
Move editor UI into the app and release verified Core dependencies (#14)
2026-10-11 19:59:40 +00:00

241 lines
8.0 KiB
Dart

import 'dart:async';
import 'package:cutdex_core/timeline/model.dart';
import 'package:flutter/material.dart';
import '../../l10n/l10n.dart';
import 'package:cutdex_ui/icons.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,
AppIcons.seekStart,
context.l10n.previewGoToStart,
enabled ? () => widget.onSeek!(0) : null,
),
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
_button(
context,
AppIcons.previousFrame,
context.l10n.previewPreviousFrame,
enabled && _position > 0 ? () => _step(-1) : null,
),
_button(
context,
widget.playing ? AppIcons.pause : AppIcons.play,
widget.playing ? context.l10n.pause : context.l10n.play,
widget.onPlayPause,
size: 32,
),
_button(
context,
AppIcons.nextFrame,
context.l10n.previewNextFrame,
enabled && _position < widget.durationTick
? () => _step(1)
: null,
),
],
),
Align(
alignment: Alignment.centerRight,
child: _button(
context,
AppIcons.exitFullscreen,
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';
}
}