MiniPlayer 仅在 Flutter 中的选项卡之间切换时显示

时间:2021-07-20 00:45:57

标签: flutter tabs dismiss

我在 Flutter 中创建了一个 Miniplayer,如下所示:

Miniplayer(
      controller: miniplayerController,
      minHeight: 60,
      onDismissed: (){
        context.read(selectedVideoProvider).state = null;
      },
      maxHeight: size.height - topPadding - 60,
      builder: (height, percentage){

        if (selectedVideo == null) {
          return const SizedBox.shrink();
        }

        if (height <= size.width / 16 * 9){
          return Row(
            children: [
              Text('This is a miniplayer'),
              IconButton(
                onPressed: (){
                  context.read(selectedVideoProvider).state = null;
                },
                icon: Icon(Icons.close)
              )
            ],
          );
        }
            
        return AnotherScreen();
      }
    );

正如您所看到的,我有一个 selectedVideoProvider StateProvider(我使用 flutter_riverpod 进行状态管理)。我还用一个 Miniplayer 小部件包裹了我的 Visibility

Consumer(
      builder: (context, watch, _){
        final selectedVideo = watch(selectedVideoProvider).state;

        
        return Visibility(maintainState: true, visible: selectedVideo != null, child: MyMiniplayerWidget());
      }
    ),

这是应用程序的屏幕: enter image description here

当我在 ListView 中单击这些图片时,会出现

迷你播放器。当我第一次单击时,一切正常(迷你播放器显示正确)。但是,当我关闭我的迷你播放器时,我无法通过单击另一张图片来打开一个新的迷你播放器。只有当我转到另一个选项卡(选项卡在我的 bottom navigation bar 上)然后返回此屏幕时,迷你播放器 才会出现 MIN 大小

enter image description here

但我希望它在我点击图片时弹出。同样,当我第一次点击图片时,一切都很好。

我的代码有什么问题?为什么 miniplayer 仅在我在选项卡之间切换时出现?

附注。如果我让 maintainState = false 在我的 Visibility 小部件迷你播放器中点击图片后立即出现,但是它以最小尺寸出现,但我希望它以最大尺寸出现。如果我制作

,您能否也解释一下为什么它不起作用
context.read(miniPlayerControllerProvider).state.animateToHeight(state: PanelState.MAX);

当我点击图片时(这是我的 miniplayerController 的 StateProvider)(这行代码使我的 miniplayer 在 maintainState = true 中点击图片时显示为 MAX 大小1}} 小部件)?

0 个答案:

没有答案