151 lines
4.4 KiB
Dart
151 lines
4.4 KiB
Dart
import 'dart:io' show Platform;
|
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
|
import 'video_viewer_web.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:video_player/video_player.dart';
|
|
import '../theme/app_theme.dart';
|
|
|
|
class VideoViewer extends StatefulWidget {
|
|
final String videoUrl;
|
|
final String fileName;
|
|
|
|
const VideoViewer({
|
|
super.key,
|
|
required this.videoUrl,
|
|
required this.fileName,
|
|
});
|
|
|
|
@override
|
|
State<VideoViewer> createState() => _VideoViewerState();
|
|
}
|
|
|
|
class _VideoViewerState extends State<VideoViewer> {
|
|
late VideoPlayerController _controller;
|
|
bool _isInitialized = false;
|
|
bool _isError = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = VideoPlayerController.networkUrl(Uri.parse(widget.videoUrl))
|
|
..initialize()
|
|
.then((_) {
|
|
if (mounted) setState(() => _isInitialized = true);
|
|
})
|
|
.catchError((_) {
|
|
if (mounted) setState(() => _isError = true);
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (kIsWeb) {
|
|
// Use web-specific video viewer
|
|
return VideoViewerWeb(
|
|
videoUrl: widget.videoUrl,
|
|
fileName: widget.fileName,
|
|
);
|
|
}
|
|
return Dialog(
|
|
backgroundColor: Colors.transparent,
|
|
child: ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 700, maxHeight: 500),
|
|
child: Container(
|
|
decoration: AppTheme.glassDecoration,
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
widget.fileName,
|
|
style: const TextStyle(
|
|
color: AppTheme.primaryText,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 18,
|
|
),
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.close, color: AppTheme.primaryText),
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
if (_isError)
|
|
const Text(
|
|
'Failed to load video',
|
|
style: TextStyle(color: Colors.red),
|
|
)
|
|
else if (!_isInitialized)
|
|
const Center(
|
|
child: CircularProgressIndicator(color: AppTheme.accentColor),
|
|
)
|
|
else
|
|
AspectRatio(
|
|
aspectRatio: _controller.value.aspectRatio,
|
|
child: Stack(
|
|
alignment: Alignment.bottomCenter,
|
|
children: [
|
|
VideoPlayer(_controller),
|
|
_ControlsOverlay(controller: _controller),
|
|
VideoProgressIndicator(
|
|
_controller,
|
|
allowScrubbing: true,
|
|
colors: VideoProgressColors(
|
|
playedColor: AppTheme.accentColor,
|
|
backgroundColor: AppTheme.secondaryText.withValues(
|
|
alpha: 0.2,
|
|
),
|
|
bufferedColor: AppTheme.secondaryText.withValues(
|
|
alpha: 0.5,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ControlsOverlay extends StatelessWidget {
|
|
final VideoPlayerController controller;
|
|
const _ControlsOverlay({required this.controller});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: () {
|
|
controller.value.isPlaying ? controller.pause() : controller.play();
|
|
},
|
|
child: Stack(
|
|
children: [
|
|
if (!controller.value.isPlaying)
|
|
Center(
|
|
child: Icon(
|
|
Icons.play_arrow,
|
|
size: 64,
|
|
color: AppTheme.accentColor.withValues(alpha: 0.8),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|