feat: 接收自定义组件传入

This commit is contained in:
guozhigq
2024-03-11 23:03:50 +08:00
parent 7b15f19895
commit b5a46d1be0
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

@ -35,6 +35,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,
}); });
@ -43,6 +45,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();
@ -311,7 +317,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,
@ -320,8 +326,17 @@ 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++) {
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]]!); list.add(videoProgressWidgets[userSpecifyItem[i]]!);
} }
}
return list; return list;
} }