From 3bb8c1acdf4635696fc86df53c3d17a468f6f352 Mon Sep 17 00:00:00 2001 From: NBA2K1 <78034913+NBA2K1@users.noreply.github.com> Date: Sat, 17 May 2025 04:56:53 +0200 Subject: [PATCH] Reduce Code duplication --- lib/modules/anime/anime_player_view.dart | 138 +++++++++-------------- 1 file changed, 52 insertions(+), 86 deletions(-) diff --git a/lib/modules/anime/anime_player_view.dart b/lib/modules/anime/anime_player_view.dart index 951b5b29..420a0319 100644 --- a/lib/modules/anime/anime_player_view.dart +++ b/lib/modules/anime/anime_player_view.dart @@ -848,60 +848,7 @@ class _AnimeStreamPageState extends riv.ConsumerState padding: const EdgeInsets.symmetric(horizontal: 8), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - _seekToWidget(), - Row( - children: [ - IconButton( - padding: const EdgeInsets.all(5), - onPressed: () => _videoSettingDraggableMenu(context), - icon: const Icon( - Icons.video_settings, - color: Colors.white, - ), - ), - TextButton( - child: ValueListenableBuilder( - valueListenable: _playbackSpeed, - builder: (context, value, child) { - return Text( - "${value}x", - style: const TextStyle(color: Colors.white), - ); - }, - ), - onPressed: () { - _togglePlaybackSpeed(); - }, - ), - IconButton( - icon: const Icon( - Icons.fit_screen_outlined, - color: Colors.white, - ), - onPressed: () async { - _changeFitLabel(ref); - }, - ), - ValueListenableBuilder( - valueListenable: _enterFullScreen, - builder: (context, snapshot, _) { - return IconButton( - onPressed: () { - _setLandscapeMode(!snapshot); - _enterFullScreen.value = !snapshot; - }, - icon: Icon( - snapshot ? Icons.fullscreen_exit : Icons.fullscreen, - ), - iconSize: 25, - color: Colors.white, - ); - }, - ), - ], - ), - ], + children: [_seekToWidget(), _buildSettingsButtons(context)], ), ), ], @@ -1048,44 +995,63 @@ class _AnimeStreamPageState extends riv.ConsumerState ), ], ), - Row( - children: [ - IconButton( - onPressed: () => _videoSettingDraggableMenu(context), - icon: const Icon(Icons.video_settings, color: Colors.white), - ), - TextButton( - child: ValueListenableBuilder( - valueListenable: _playbackSpeed, - builder: (context, value, child) { - return Text( - "${value}x", - style: const TextStyle(color: Colors.white), - ); - }, - ), - onPressed: () { - _togglePlaybackSpeed(); - }, - ), - IconButton( - icon: const Icon( - Icons.fit_screen_outlined, - color: Colors.white, - ), - onPressed: () async { - _changeFitLabel(ref); - }, - ), - CustomMaterialDesktopFullscreenButton(controller: _controller), - ], - ), + _buildSettingsButtons(context), ], ), ], ); } + /// helper method for _mobileBottomButtonBar() and _desktopBottomButtonBar() + Widget _buildSettingsButtons(BuildContext context) { + return Row( + children: [ + IconButton( + padding: _isDesktop ? EdgeInsets.zero : const EdgeInsets.all(5), + onPressed: () => _videoSettingDraggableMenu(context), + icon: const Icon(Icons.video_settings, color: Colors.white), + ), + TextButton( + child: ValueListenableBuilder( + valueListenable: _playbackSpeed, + builder: (context, value, child) { + return Text( + "${value}x", + style: const TextStyle(color: Colors.white), + ); + }, + ), + onPressed: () { + _togglePlaybackSpeed(); + }, + ), + IconButton( + icon: const Icon(Icons.fit_screen_outlined, color: Colors.white), + onPressed: () async { + _changeFitLabel(ref); + }, + ), + if (_isDesktop) + CustomMaterialDesktopFullscreenButton(controller: _controller) + else + ValueListenableBuilder( + valueListenable: _enterFullScreen, + builder: (context, snapshot, _) { + return IconButton( + onPressed: () { + _setLandscapeMode(!snapshot); + _enterFullScreen.value = !snapshot; + }, + icon: Icon(snapshot ? Icons.fullscreen_exit : Icons.fullscreen), + iconSize: 25, + color: Colors.white, + ); + }, + ), + ], + ); + } + Widget _topButtonBar(BuildContext context) { return ValueListenableBuilder( valueListenable: _enterFullScreen,