mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 08:31:19 +00:00
84 lines
2.3 KiB
Dart
84 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:tablet_app/Components/loading_common.dart';
|
|
import 'package:video_player/video_player.dart';
|
|
import '../../constants.dart';
|
|
|
|
class VideoViewer extends StatefulWidget {
|
|
final String videoUrl;
|
|
VideoViewer({required this.videoUrl});
|
|
|
|
@override
|
|
_VideoViewer createState() => _VideoViewer();
|
|
}
|
|
|
|
class _VideoViewer extends State<VideoViewer> {
|
|
late VideoPlayerController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = VideoPlayerController.networkUrl(Uri.parse(
|
|
widget.videoUrl))
|
|
..initialize().then((_) {
|
|
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
|
|
setState(() {});
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
_controller.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
Center(
|
|
child: InkWell(
|
|
onTap: () {
|
|
setState(() {
|
|
if(_controller.value.isInitialized) {
|
|
if(_controller.value.isPlaying) {
|
|
_controller.pause();
|
|
} else {
|
|
_controller.play();
|
|
}
|
|
}
|
|
});
|
|
},
|
|
child: _controller.value.isInitialized
|
|
? AspectRatio(
|
|
aspectRatio: _controller.value.aspectRatio,
|
|
child: VideoPlayer(_controller),
|
|
)
|
|
: Center(
|
|
child: Container(
|
|
child: LoadingCommon()
|
|
)
|
|
),
|
|
),
|
|
),
|
|
if(!_controller.value.isPlaying && _controller.value.isInitialized)
|
|
Center(
|
|
child: FloatingActionButton(
|
|
backgroundColor: kTestSecondColor.withOpacity(0.8),
|
|
onPressed: () {
|
|
setState(() {
|
|
_controller.value.isPlaying
|
|
? _controller.pause()
|
|
: _controller.play();
|
|
});
|
|
},
|
|
child: Icon(
|
|
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
|
|
color: Colors.white),
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|