flutter_integrated_whb/lib/customWidget/full_screen_video_page.dart

86 lines
2.5 KiB
Dart
Raw Normal View History

2025-07-11 11:03:21 +08:00
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
2025-08-19 11:06:16 +08:00
import 'package:chewie/chewie.dart';
2025-07-11 11:03:21 +08:00
2025-08-19 11:06:16 +08:00
/// 弹窗组件Chewie 版 VideoPlayerPopup
2025-07-11 11:03:21 +08:00
class VideoPlayerPopup extends StatefulWidget {
final String videoUrl;
const VideoPlayerPopup({Key? key, required this.videoUrl}) : super(key: key);
@override
State<VideoPlayerPopup> createState() => _VideoPlayerPopupState();
}
class _VideoPlayerPopupState extends State<VideoPlayerPopup> {
2025-08-19 11:06:16 +08:00
late VideoPlayerController _videoController;
ChewieController? _chewieController;
2025-07-11 11:03:21 +08:00
@override
void initState() {
super.initState();
2025-08-19 11:06:16 +08:00
_videoController = VideoPlayerController.networkUrl(Uri.parse(widget.videoUrl))
..initialize().then((_) {
2025-07-11 11:03:21 +08:00
setState(() {});
});
2025-08-19 11:06:16 +08:00
_chewieController = ChewieController(
videoPlayerController: _videoController,
autoPlay: true,
looping: false,
showOptions:false,
allowFullScreen: true,
allowPlaybackSpeedChanging: true,
allowMuting: true,
showControlsOnInitialize: true,
materialProgressColors: ChewieProgressColors(playedColor: Colors.blue,backgroundColor: Colors.white, handleColor:Colors.blue,bufferedColor:Colors.red),
aspectRatio: _videoController.value.aspectRatio,
);
2025-07-11 11:03:21 +08:00
}
@override
void dispose() {
2025-08-19 11:06:16 +08:00
_chewieController?.dispose();
_videoController.dispose();
2025-07-11 11:03:21 +08:00
super.dispose();
}
@override
Widget build(BuildContext context) {
return Center(
child: Material(
color: Colors.transparent,
child: Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.9,
2025-08-19 11:06:16 +08:00
maxHeight: 500,
2025-07-11 11:03:21 +08:00
),
decoration: BoxDecoration(
2025-08-19 11:06:16 +08:00
color: Colors.black,
2025-07-11 11:03:21 +08:00
borderRadius: BorderRadius.circular(8),
),
child: Stack(
children: [
2025-08-19 11:06:16 +08:00
// 视频播放器
if (_chewieController != null &&
_videoController.value.isInitialized)
Chewie(controller: _chewieController!)
2025-07-11 11:03:21 +08:00
else
const Center(child: CircularProgressIndicator()),
// 关闭按钮
Positioned(
top: 4,
right: 4,
child: IconButton(
2025-08-19 11:06:16 +08:00
icon: const Icon(Icons.close, color: Colors.white),
2025-07-11 11:03:21 +08:00
onPressed: () => Navigator.of(context).pop(),
),
),
],
),
),
),
);
}
}