Files
Siro/siro_driver/lib/views/home/Captin/About Us/video_page.dart
T

192 lines
6.0 KiB
Dart
Executable File

import 'package:siro_driver/constant/info.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:video_player/video_player.dart';
import 'package:youtube_player_flutter/youtube_player_flutter.dart';
import '../../../../controller/home/captin/help/video_controller.dart';
import '../../../widgets/ui/siro_ui.dart';
class VideoListPage extends StatelessWidget {
VideoListPage({super.key});
final VideoController videoController = Get.put(VideoController());
@override
Widget build(BuildContext context) {
return SiroPage(
title: 'Videos Tutorials'.tr,
padding: SiroUi.pageInsets,
body: GetBuilder<VideoController>(
builder: (videoController) {
if (videoController.videos.isEmpty) {
return SiroEmptyState(
icon: Icons.video_library_rounded,
title: 'No videos available'.tr,
);
}
return ListView.builder(
itemCount: videoController.videos.length,
itemBuilder: (context, index) {
final video = videoController.videos[index];
return SiroCard(
onTap: () =>
Get.to(() => VideoPlayerPage1(videoUrl: video['url'])),
child: Row(
children: [
SiroIconBadge(Icons.play_arrow_rounded,
color: SiroUi.interactive(context), size: 24),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
video['title'] ?? '',
style: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(fontWeight: FontWeight.bold),
),
const SizedBox(height: 3),
Text(
video['description'] ?? '',
style: Theme.of(context).textTheme.bodySmall,
),
],
),
),
Icon(Icons.arrow_forward_ios_rounded,
size: 13, color: SiroUi.subtle(context)),
],
),
);
},
);
},
),
);
}
}
class VideoPlayerPage extends StatelessWidget {
final String videoUrl;
VideoPlayerPage({super.key, required this.videoUrl});
final VideoController videoController = Get.put(VideoController());
@override
Widget build(BuildContext context) {
// Initialize the video when the page is loaded
videoController.initializeVideo(videoUrl);
return SiroPage(
title: AppInformation.appName,
body: Center(
child: GetBuilder<VideoController>(
builder: (controller) {
if (!controller.videoPlayerController.value.isInitialized) {
return const SiroLoading();
}
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Video player widget
AspectRatio(
aspectRatio:
controller.videoPlayerController.value.aspectRatio,
child: VideoPlayer(controller.videoPlayerController),
),
const SizedBox(height: 20),
// Play/pause button
IconButton.filled(
iconSize: 32,
onPressed: () {
if (controller.videoPlayerController.value.isPlaying) {
controller.pause();
} else {
controller.play();
}
},
icon: Icon(
controller.videoPlayerController.value.isPlaying
? Icons.pause_rounded
: Icons.play_arrow_rounded,
),
),
],
);
},
),
),
);
}
}
class VideoPlayerPage1 extends StatelessWidget {
final String videoUrl;
const VideoPlayerPage1({super.key, required this.videoUrl});
@override
Widget build(BuildContext context) {
// Extract the video ID from the URL
final String? videoId = YoutubePlayer.convertUrlToId(videoUrl);
// رابط غير صالح كان يرمي `Null check operator used on a null value`
// ويُسقط الشاشة بيضاء بدل رسالة مفهومة.
if (videoId == null) {
return SiroPage(
title: AppInformation.appName,
body: SiroEmptyState(
icon: Icons.videocam_off_rounded,
title: 'Video unavailable'.tr,
),
);
}
final YoutubePlayerController controller = YoutubePlayerController(
initialVideoId: videoId,
flags: const YoutubePlayerFlags(
autoPlay: true,
loop: true,
mute: false,
captionLanguage: 'ar',
),
);
return Scaffold(
backgroundColor: Colors.black,
body: Stack(
children: [
// Full-screen YouTube player
Positioned.fill(
child: YoutubePlayer(
controller: controller,
showVideoProgressIndicator: true,
),
),
// زر الخروج — كان `left` ثابتاً فيقع تحت الإبهام الخطأ في العربية
SafeArea(
child: PositionedDirectional(
top: 8,
start: 8,
child: CircleAvatar(
backgroundColor: Colors.black45,
child: IconButton(
icon: const Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => Navigator.pop(context),
),
),
),
),
],
),
);
}
}