From bf77ccf8e3181d230fa6f6298c9a32f7cd9aab44 Mon Sep 17 00:00:00 2001 From: Flummi Date: Thu, 5 Jun 2025 11:15:16 +0200 Subject: [PATCH] actionchip lel --- lib/screens/DetailView.dart | 55 +++++++------- lib/widgets/VideoOverlay.dart | 131 +++++++++++++++++----------------- lib/widgets/VideoWidget.dart | 2 +- 3 files changed, 97 insertions(+), 91 deletions(-) diff --git a/lib/screens/DetailView.dart b/lib/screens/DetailView.dart index d5a3be0..25ef09c 100644 --- a/lib/screens/DetailView.dart +++ b/lib/screens/DetailView.dart @@ -99,12 +99,13 @@ class _DetailViewState extends State { tag: _tagname, ); if (mounted && newMedia.isNotEmpty) { - setState(() => mediaItems.addAll(newMedia)); + setState(() { + mediaItems.addAll(newMedia); + isLoading = false; + }); } } catch (e) { - _showError("Fehler beim Laden weiterer Medien: $e"); - } finally { - setState(() => isLoading = false); + _showError("Ein unerwarteter Fehler ist aufgetreten: $e"); } } @@ -123,11 +124,11 @@ class _DetailViewState extends State { } void _showError(String message) { - if (mounted) { - ScaffoldMessenger.of( - context, - ).showSnackBar(SnackBar(content: Text(message))); - } + if (!mounted) return; + + final messenger = ScaffoldMessenger.of(context); + messenger.hideCurrentSnackBar(); + messenger.showSnackBar(SnackBar(content: Text(message))); } @override @@ -219,23 +220,27 @@ class _DetailViewState extends State { alignment: WrapAlignment.center, spacing: 5.0, children: item.tags.map((tag) { - return GestureDetector( - onTap: () { - if (tag.tag == 'sfw' || tag.tag == 'nsfw') return; - setState(() { - _tagname = tag.tag; - Navigator.pop(context, _tagname); - }); - }, - child: Chip( - label: Text(tag.tag), - backgroundColor: switch (tag.id) { - 1 => Colors.green, - 2 => Colors.red, - _ => const Color(0xFF090909), - }, - labelStyle: const TextStyle(color: Colors.white), + return ActionChip( + label: Text( + tag.tag, + style: const TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + ), ), + backgroundColor: switch (tag.id) { + 1 => Colors.green, + 2 => Colors.red, + _ => const Color(0xFF090909), + }, + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + onPressed: () async { + if (tag.tag == 'sfw' || tag.tag == 'nsfw') return; + setState(() => Navigator.pop(context, tag.tag)); + }, ); }).toList(), ), diff --git a/lib/widgets/VideoOverlay.dart b/lib/widgets/VideoOverlay.dart index 428cc3c..09872e5 100644 --- a/lib/widgets/VideoOverlay.dart +++ b/lib/widgets/VideoOverlay.dart @@ -22,9 +22,10 @@ class VideoControlsOverlay extends StatelessWidget { children: [ _ControlButton(Icons.replay_10, () { button(); - controller.seekTo( - controller.value.position - Duration(seconds: 10), - ); + Duration newPosition = + controller.value.position - const Duration(seconds: 10); + if (newPosition < Duration.zero) newPosition = Duration.zero; + controller.seekTo(newPosition); }), SizedBox(width: 40), _ControlButton( @@ -40,17 +41,75 @@ class VideoControlsOverlay extends StatelessWidget { SizedBox(width: 40), _ControlButton(Icons.forward_10, () { button(); - controller.seekTo( - controller.value.position + Duration(seconds: 10), - ); + Duration newPosition = + controller.value.position + const Duration(seconds: 10); + if (newPosition > controller.value.duration) { + newPosition = controller.value.duration; + } + controller.seekTo(newPosition); }), ], ), ), - _ProgressIndicator(controller: controller) + Align( + alignment: Alignment.bottomCenter, + child: Padding( + padding: const EdgeInsets.only(bottom: 0), + child: Stack( + clipBehavior: Clip.none, + children: [ + Positioned( + left: 10, + bottom: 12, + child: Text( + '${_formatDuration(controller.value.position)} / ${_formatDuration(controller.value.duration)}', + style: TextStyle(color: Colors.white), + ), + ), + Listener( + onPointerDown: (_) { + button(); + }, + child: VideoProgressIndicator( + controller, + allowScrubbing: true, + padding: const EdgeInsets.only(top: 25.0), + colors: const VideoProgressColors( + playedColor: Colors.red, + backgroundColor: Colors.grey, + bufferedColor: Colors.white54, + ), + ), + ), + Positioned( + left: + (controller.value.position.inMilliseconds / + controller.value.duration.inMilliseconds) * + MediaQuery.of(context).size.width - + 6, + bottom: -4, + child: Container( + width: 12, + height: 12, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Colors.red, + border: Border.all(color: Colors.red, width: 2), + ), + ), + ), + ], + ), + ), + ), ], ); } + + String _formatDuration(Duration duration) { + String twoDigits(int n) => n.toString().padLeft(2, '0'); + return "${twoDigits(duration.inMinutes % 60)}:${twoDigits(duration.inSeconds % 60)}"; + } } class _ControlButton extends StatelessWidget { @@ -74,61 +133,3 @@ class _ControlButton extends StatelessWidget { ); } } - -class _ProgressIndicator extends StatelessWidget { - final CachedVideoPlayerPlusController controller; - - const _ProgressIndicator({required this.controller}); - - @override - Widget build(BuildContext context) { - return Align( - alignment: Alignment.bottomCenter, - child: Stack( - clipBehavior: Clip.none, - children: [ - VideoProgressIndicator( - controller, - allowScrubbing: true, - padding: const EdgeInsets.only(top: 25.0), - colors: VideoProgressColors( - playedColor: Colors.red, - backgroundColor: Colors.grey, - bufferedColor: Colors.white54, - ), - ), - Positioned( - left: - (controller.value.position.inMilliseconds / - controller.value.duration.inMilliseconds) * - MediaQuery.of(context).size.width - - 6, - bottom: -4, - child: Container( - width: 12, - height: 12, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.red, - border: Border.all(color: Colors.red, width: 2), - ), - ), - ), - Positioned( - left: 16, - bottom: 10, - child: Text( - '${_formatDuration(controller.value.position)} / ${_formatDuration(controller.value.duration)}', - style: TextStyle(color: Colors.white), - ), - ), - ], - ), - ); - } - - String _formatDuration(Duration duration) { - String twoDigits(int n) => n.toString().padLeft(2, '0'); - return "${twoDigits(duration.inMinutes % 60)}:${twoDigits(duration.inSeconds % 60)}"; - } -} diff --git a/lib/widgets/VideoWidget.dart b/lib/widgets/VideoWidget.dart index d148af2..6c6a755 100644 --- a/lib/widgets/VideoWidget.dart +++ b/lib/widgets/VideoWidget.dart @@ -64,7 +64,7 @@ class _VideoWidgetState extends State { if (_showControls) { _hideControlsTimer?.cancel(); - _hideControlsTimer = Timer(Duration(seconds: 5), () { + _hideControlsTimer = Timer(Duration(seconds: 2), () { setState(() => _showControls = false); }); }