fist commit ftc staff app clone
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ftc_mobile_app/ftc_mobile_app.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
enum VideoSourceType { file, network }
|
||||
|
||||
class VideoPlayerWidget extends StatefulWidget {
|
||||
final String path;
|
||||
final VideoSourceType type;
|
||||
|
||||
const VideoPlayerWidget({
|
||||
super.key,
|
||||
required this.path,
|
||||
required this.type,
|
||||
});
|
||||
|
||||
@override
|
||||
State<VideoPlayerWidget> createState() => _VideoPlayerWidgetState();
|
||||
}
|
||||
|
||||
class _VideoPlayerWidgetState extends State<VideoPlayerWidget> {
|
||||
VideoPlayerController? _videoPlayerController;
|
||||
final RxBool isInitialized = false.obs;
|
||||
final RxBool isError = false.obs;
|
||||
final RxBool isPlaying = false.obs;
|
||||
double aspectRatio = 16.0 / 9.0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
print("Video path: ${widget.path}");
|
||||
if (widget.type == VideoSourceType.network) {
|
||||
print("VideoSourceType.network");
|
||||
_videoPlayerController =
|
||||
VideoPlayerController.networkUrl(Uri.parse(widget.path));
|
||||
} else {
|
||||
print("VideoSourceType.file");
|
||||
_videoPlayerController = VideoPlayerController.file(File(widget.path));
|
||||
}
|
||||
|
||||
_videoPlayerController?.initialize().then((_) {
|
||||
isInitialized.value = true;
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AspectRatio(
|
||||
aspectRatio: aspectRatio,
|
||||
child: Obx(() {
|
||||
return (isError())
|
||||
? FrequentFunctions.centerText(text: "Something went wrong")
|
||||
: isInitialized.isFalse
|
||||
? FrequentFunctions.centerText(text: "Loading video...")
|
||||
: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: VideoPlayer(_videoPlayerController!),
|
||||
),
|
||||
Center(
|
||||
child: Obx(() {
|
||||
return (isPlaying())
|
||||
? FrequentFunctions.noWidget
|
||||
: InkWell(
|
||||
onTap: () {
|
||||
if (isPlaying.isFalse) {
|
||||
isPlaying.value = true;
|
||||
_videoPlayerController?.play();
|
||||
}
|
||||
},
|
||||
child: Icon(
|
||||
Icons.play_circle,
|
||||
color: Get.theme.primaryColor,
|
||||
size: 56.r,
|
||||
),
|
||||
);
|
||||
}),
|
||||
)
|
||||
],
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_videoPlayerController?.dispose();
|
||||
_videoPlayerController = null;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user