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, fit,
speed, speed,
fullscreen, fullscreen,
custom,
} }

View File

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