feat: 接收自定义组件传入

This commit is contained in:
guozhigq
2024-03-11 23:03:50 +08:00
parent 6fdfcb888d
commit ab10223eca
2 changed files with 18 additions and 2 deletions

View File

@ -7,4 +7,5 @@ enum BottomControlType {
fit,
speed,
fullscreen,
custom,
}

View File

@ -34,6 +34,8 @@ class PLVideoPlayer extends StatefulWidget {
this.bottomControl,
this.danmuWidget,
this.bottomList,
this.customWidget,
this.customWidgets,
super.key,
});
@ -42,6 +44,10 @@ class PLVideoPlayer extends StatefulWidget {
final PreferredSizeWidget? bottomControl;
final Widget? danmuWidget;
final List<BottomControlType>? bottomList;
// List<Widget> or Widget
final Widget? customWidget;
final List<Widget>? customWidgets;
@override
State<PLVideoPlayer> createState() => _PLVideoPlayerState();
@ -310,7 +316,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
),
};
final List<Widget> list = [];
var userSpecifyItem = widget.bottomList ??
List<BottomControlType> userSpecifyItem = widget.bottomList ??
[
BottomControlType.playOrPause,
BottomControlType.time,
@ -319,7 +325,16 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
BottomControlType.fullscreen,
];
for (var i = 0; i < userSpecifyItem.length; i++) {
list.add(videoProgressWidgets[userSpecifyItem[i]]!);
if (userSpecifyItem[i] == BottomControlType.custom) {
if (widget.customWidget != null && widget.customWidget is Widget) {
list.add(widget.customWidget!);
}
if (widget.customWidgets != null && widget.customWidgets!.isNotEmpty) {
list.addAll(widget.customWidgets!);
}
} else {
list.add(videoProgressWidgets[userSpecifyItem[i]]!);
}
}
return list;
}