feat: 分类页面优化,播放器详情处理当前集,首页的优化。图片导入。
This commit is contained in:
1 parent
4ccea08472
commit
2f1ec27802
28 files changed
+868
-568
No files matched your search
@@ -6,6 +6,7 @@ import 'package:skywood/pages/home/players/widget/sky_player_view.dart';
|
||||
import 'package:skywood/utils/models/drama/skywood_detail.dart';
|
||||
import 'package:skywood/utils/models/drama/skywood_drama.dart';
|
||||
import 'package:skywood/utils/models/drama/skywood_home.dart';
|
||||
import 'package:skywood/utils/tools/app_toast.dart';
|
||||
import 'package:skywood/utils/tools/widgets/sky_app_bar.dart';
|
||||
import 'package:skywood/utils/tools/widgets/sky_common_widget.dart';
|
||||
|
||||
@@ -34,10 +35,13 @@ class _DramaDetailPageState extends State<DramaDetailPage> {
|
||||
}
|
||||
|
||||
void _getDetailDrama() {
|
||||
print('currentEpisode===${widget.dramaBean.currentEpisode}');
|
||||
AppToast.showLottieLoading();
|
||||
PlayClient.getVideoDetail(
|
||||
shortPlayId: widget.dramaBean.shortPlayId ?? 0,
|
||||
shortPlayVideoId: widget.dramaBean.shortPlayVideoId ?? 0
|
||||
).then((value) {
|
||||
AppToast.dismiss();
|
||||
setState(() {
|
||||
_detailBean = value;
|
||||
});
|
||||
@@ -57,11 +61,10 @@ class _DramaDetailPageState extends State<DramaDetailPage> {
|
||||
children: [
|
||||
SizedBox(width: double.infinity, height: double.infinity),
|
||||
|
||||
if (widget.dramaBean.videoUrl != null)
|
||||
if (_detailBean != null)
|
||||
Positioned(
|
||||
bottom: 0, left: 0, right: 0, top: 0,
|
||||
child: SkyPlayerView(
|
||||
videoUrl: widget.dramaBean.videoUrl!,
|
||||
detailBean: _detailBean,
|
||||
dramaBean: widget.dramaBean,
|
||||
),
|
||||
|
||||
@@ -6,10 +6,15 @@ import 'package:skywood/utils/models/drama/skywood_episode.dart';
|
||||
import 'package:skywood/utils/tools/widgets/sky_common_widget.dart';
|
||||
|
||||
class DramaEspPage extends StatefulWidget {
|
||||
const DramaEspPage({super.key, required this.detail, this.currentEpisode});
|
||||
const DramaEspPage({super.key,
|
||||
required this.detail,
|
||||
this.currentEpisode,
|
||||
this.onSelectedEpisode,
|
||||
});
|
||||
|
||||
final SkywoodDetail detail;
|
||||
final int? currentEpisode;
|
||||
final Function(int)? onSelectedEpisode;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@@ -182,6 +187,7 @@ class _DramaEspPageState extends State<DramaEspPage> {
|
||||
setState(() {
|
||||
_selectedEpisode = episode.episode;
|
||||
});
|
||||
widget.onSelectedEpisode?.call(_selectedEpisode);
|
||||
},
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
|
||||
@@ -4,22 +4,25 @@ import 'package:skywood/main/lib_file.dart';
|
||||
import 'package:skywood/pages/home/players/page/drama_esp_page.dart';
|
||||
import 'package:skywood/utils/models/drama/skywood_detail.dart';
|
||||
import 'package:skywood/utils/models/drama/skywood_drama.dart';
|
||||
import 'package:skywood/utils/models/drama/skywood_episode.dart';
|
||||
import 'package:skywood/utils/tools/widgets/sky_common_widget.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
/// 视频播放器
|
||||
class SkyPlayerView extends StatefulWidget {
|
||||
final String videoUrl;
|
||||
// final String videoUrl;
|
||||
final bool autoPlay;
|
||||
final SkywoodDetail? detailBean;
|
||||
final SkywoodDrama dramaBean;
|
||||
final int? currentEpisode;
|
||||
|
||||
const SkyPlayerView({
|
||||
super.key,
|
||||
required this.videoUrl,
|
||||
// required this.videoUrl,
|
||||
this.autoPlay = true,
|
||||
this.detailBean,
|
||||
required this.dramaBean,
|
||||
this.currentEpisode,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -36,6 +39,7 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
Duration _currentPosition = Duration.zero;
|
||||
Duration _totalDuration = Duration.zero;
|
||||
bool _isLiked = false;
|
||||
SkywoodEpisode? _currentEpisode;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -43,14 +47,14 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
_initializePlayer();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SkyPlayerView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.videoUrl != widget.videoUrl) {
|
||||
_disposeController();
|
||||
_initializePlayer();
|
||||
}
|
||||
}
|
||||
// @override
|
||||
// void didUpdateWidget(SkyPlayerView oldWidget) {
|
||||
// super.didUpdateWidget(oldWidget);
|
||||
// if (oldWidget.videoUrl != widget.videoUrl) {
|
||||
// _disposeController();
|
||||
// _initializePlayer();
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<void> _initializePlayer() async {
|
||||
setState(() {
|
||||
@@ -62,8 +66,17 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
_isLiked = widget.dramaBean.isCollect ?? false;
|
||||
});
|
||||
|
||||
int _esp = widget.currentEpisode ?? 0;
|
||||
String videoUrl = '';
|
||||
if (widget.detailBean != null) {
|
||||
if (widget.detailBean!.episodeList.isNotEmpty) {
|
||||
videoUrl = widget.detailBean!.episodeList[_esp].videoUrl;
|
||||
_currentEpisode = widget.detailBean!.episodeList[_esp];
|
||||
}
|
||||
}
|
||||
|
||||
final controller = VideoPlayerController.networkUrl(
|
||||
Uri.parse(widget.videoUrl),
|
||||
Uri.parse(videoUrl),
|
||||
);
|
||||
_controller = controller;
|
||||
_controllerCreated = true;
|
||||
@@ -181,8 +194,8 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
Widget _buildLoadingView() {
|
||||
return Container(
|
||||
color: Colors.black,
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(color: Colors.white),
|
||||
child: Center(
|
||||
child: HelpImg.asset(ConstImg.loading, width: 110),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -211,16 +224,17 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
}
|
||||
|
||||
void _collectionDrama() {
|
||||
if (_currentEpisode == null) return;
|
||||
if (_isLiked) {
|
||||
PlayClient.cancelCollect(shortPlayId: widget.dramaBean.shortPlayId??0).then((value) {
|
||||
PlayClient.cancelCollect(shortPlayId: _currentEpisode!.shortPlayId).then((value) {
|
||||
setState(() {
|
||||
_isLiked = value;
|
||||
});
|
||||
});
|
||||
} else {
|
||||
PlayClient.collect(
|
||||
shortPlayId: widget.dramaBean.shortPlayId??0,
|
||||
videoId: widget.dramaBean.shortPlayVideoId ?? 0,
|
||||
shortPlayId: _currentEpisode!.shortPlayId,
|
||||
videoId: _currentEpisode!.shortPlayVideoId,
|
||||
).then((value) {
|
||||
setState(() {
|
||||
_isLiked = value;
|
||||
@@ -231,7 +245,7 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
|
||||
Widget _buildBottomView() {
|
||||
SkywoodDetail detail = widget.detailBean!;
|
||||
final int currentEpisode = _currentEpisode(detail);
|
||||
final int currentEpisode = _getCurrentEpisode(detail);
|
||||
final int totalEpisode = _episodeTotal(detail);
|
||||
|
||||
return Container(
|
||||
@@ -292,6 +306,14 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
child: DramaEspPage(
|
||||
detail: detail,
|
||||
currentEpisode: currentEpisode,
|
||||
onSelectedEpisode: (episode) {
|
||||
|
||||
if (widget.detailBean != null) {
|
||||
if (widget.detailBean!.episodeList.isNotEmpty) {
|
||||
_currentEpisode = widget.detailBean!.episodeList[episode];
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -339,7 +361,9 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
child: SliderTheme(
|
||||
data: SliderThemeData(
|
||||
trackHeight: 3, // ✅ 进度条高度 3
|
||||
thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 1),
|
||||
thumbShape: _ImageThumbShape(
|
||||
imagePath: ConstImg.playTag
|
||||
),
|
||||
overlayShape: const RoundSliderOverlayShape(overlayRadius: 3),
|
||||
activeTrackColor: Colors.white, // ✅ 已播放 = 白色
|
||||
inactiveTrackColor: Colors.white.withAlpha(126), // ✅ 未播放 = 灰色
|
||||
@@ -379,7 +403,7 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
return '$minutes:$seconds';
|
||||
}
|
||||
|
||||
int _currentEpisode(SkywoodDetail detail) {
|
||||
int _getCurrentEpisode(SkywoodDetail detail) {
|
||||
final int? episode =
|
||||
detail.videoInfo?.episode ??
|
||||
detail.videoInfo?.currentEpisode ??
|
||||
@@ -394,3 +418,75 @@ class _VideoPlayerWidgetState extends State<SkyPlayerView> {
|
||||
return detail.episodeList.length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class _ImageThumbShape extends SliderComponentShape {
|
||||
final String imagePath;
|
||||
final double imageSize;
|
||||
|
||||
const _ImageThumbShape({
|
||||
required this.imagePath,
|
||||
this.imageSize = 16,
|
||||
});
|
||||
|
||||
@override
|
||||
Size getPreferredSize(bool isEnabled, bool isDiscrete) {
|
||||
return Size(imageSize, imageSize);
|
||||
}
|
||||
|
||||
@override
|
||||
void paint(
|
||||
PaintingContext context,
|
||||
Offset center, {
|
||||
required Animation<double> activationAnimation,
|
||||
required Animation<double> enableAnimation,
|
||||
required bool isDiscrete,
|
||||
required TextPainter labelPainter,
|
||||
required RenderBox parentBox,
|
||||
required SliderThemeData sliderTheme,
|
||||
required TextDirection textDirection,
|
||||
required double value,
|
||||
required double textScaleFactor,
|
||||
required Size sizeWithOverflow,
|
||||
}) {
|
||||
// 🔥 使用 Image 直接渲染图片
|
||||
final imageWidget = Image.asset(
|
||||
imagePath,
|
||||
width: imageSize,
|
||||
height: imageSize,
|
||||
);
|
||||
|
||||
// 使用 WidgetsBinding 确保图片已加载
|
||||
final image = imageWidget.image;
|
||||
final stream = image.resolve(ImageConfiguration());
|
||||
|
||||
// 添加监听器,但只在图片加载完成后绘制
|
||||
stream.addListener(ImageStreamListener((imageInfo, _) {
|
||||
final rect = Rect.fromCenter(
|
||||
center: center,
|
||||
width: imageSize,
|
||||
height: imageSize,
|
||||
);
|
||||
context.canvas.drawImageRect(
|
||||
imageInfo.image,
|
||||
Rect.fromLTWH(
|
||||
0,
|
||||
0,
|
||||
imageInfo.image.width.toDouble(),
|
||||
imageInfo.image.height.toDouble(),
|
||||
),
|
||||
rect,
|
||||
Paint(),
|
||||
);
|
||||
}, onError: (error, stackTrace) {
|
||||
// 🔥 如果图片加载失败,绘制一个默认圆点
|
||||
final paint = Paint()
|
||||
..color = Colors.white
|
||||
..style = PaintingStyle.fill;
|
||||
context.canvas.drawCircle(center, imageSize / 2, paint);
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user