Aidra Connect 10.0.2+16
Aidra Connect Mobile Application
Loading...
Searching...
No Matches
video_card.dart
Go to the documentation of this file.
1import '/core/ui/widgets/custom_card.dart';
2import '/features/elearning/domain/entities/video_entity.dart';
3import '/features/elearning/presentation/screens/news_updates_screen/widgets/expandable_text.dart';
4import 'package:flutter/material.dart';
5import 'package:flutter_screenutil/flutter_screenutil.dart';
6import 'package:hugeicons/hugeicons.dart';
7import 'package:url_launcher/url_launcher.dart';
8
9class VideoCard extends StatefulWidget {
10 const VideoCard({
11 super.key,
12 required this.video,
13 });
14
16
17 @override
18 State<VideoCard> createState() => _VideoCardState();
19}
20
21class _VideoCardState extends State<VideoCard> {
22 opslaunchVideo(String videoUrl) {
23 launchUrl(Uri.parse(videoUrl));
24 }
25
26 String getYoutubeThumbnail(String videoUrl) {
27 final Uri? uri = Uri.tryParse(videoUrl);
28 if (uri == null ||
29 !uri.host.contains('youtube.com') && !uri.host.contains('youtu.be')) {
30 throw Exception('Invalid YouTube URL');
31 }
32
33 String? videoId;
34
35 if (uri.host.contains('youtube.com')) {
36 videoId = uri.queryParameters['v'];
37 } else if (uri.host.contains('youtu.be')) {
38 videoId = uri.pathSegments.isNotEmpty ? uri.pathSegments.first : null;
39 }
40
41 if (videoId == null) {
42 return '';
43 }
44
45 return 'https://img.youtube.com/vi/$videoId/0.jpg';
46 }
47
48 @override
49 Widget build(BuildContext context) {
50 return ElevatedButton(
51 onPressed: () {
52 opslaunchVideo(widget.video.linkUrl ?? '');
53 },
54 style: ElevatedButton.styleFrom(
55 padding: EdgeInsets.zero,
56 overlayColor: Theme.of(context).colorScheme.primary,
57 ),
59 child: Column(
60 crossAxisAlignment: CrossAxisAlignment.start,
61 children: [
62 Row(
63 crossAxisAlignment: CrossAxisAlignment.start,
64 mainAxisAlignment: MainAxisAlignment.spaceBetween,
65 children: [
66 Flexible(
67 child: Text(
68 '${widget.video.name}',
69 style: Theme.of(context).textTheme.bodySmall,
70 ),
71 ),
72 SizedBox(width: 10.sp),
73 Container(
74 decoration: BoxDecoration(
75 borderRadius: BorderRadius.circular(80),
76 color: Theme.of(context).primaryColor,
77 ),
78 padding:
79 EdgeInsets.symmetric(horizontal: 7.sp, vertical: 3.sp),
80 child: Row(
81 mainAxisSize: MainAxisSize.min,
82 children: [
83 Icon(
84 HugeIcons.strokeRoundedTime02,
85 size: 12.sp,
86 color: Theme.of(context).colorScheme.onPrimary,
87 ),
88 SizedBox(width: 4.sp),
89 Text(
90 '${widget.video.videoTime}',
91 style: Theme.of(context).textTheme.bodySmall?.copyWith(
92 color: Theme.of(context).colorScheme.onPrimary,
93 fontSize: 9.5.sp,
94 fontWeight: FontWeight.bold,
95 ),
96 ),
97 ],
98 ),
99 ),
100 ],
101 ),
102 SizedBox(height: 10.sp),
103 const Divider(
104 height: 0.0,
105 ),
106 SizedBox(height: 10.sp),
107 ExpandableText(
108 text: widget.video.description ?? '',
109 maxLines: 2,
110 ),
111 SizedBox(height: 10.sp),
112 const Divider(
113 height: 0.0,
114 endIndent: 100,
115 ),
116 SizedBox(height: 10.sp),
117 Container(
118 height: 160.sp,
119 width: MediaQuery.of(context).size.width,
120 decoration: BoxDecoration(
121 borderRadius: BorderRadius.circular(5),
122 color: Theme.of(context).colorScheme.surface.withOpacity(0.3),
123 image: DecorationImage(
124 fit: BoxFit.cover,
125 image: NetworkImage(
126 getYoutubeThumbnail('${widget.video.linkUrl}'),
127 ),
128 ),
129 ),
130 child: Center(
131 child: CircleAvatar(
133 Theme.of(context).colorScheme.onSurface.withOpacity(0.11),
134 radius: 25.sp,
135 child: CircleAvatar(
136 radius: 20.sp,
137 backgroundColor: Theme.of(context)
138 .colorScheme
139 .onSurface
140 .withOpacity(0.5),
141 child: Center(
142 child: Icon(
143 HugeIcons.strokeRoundedPlay,
144 color: Theme.of(context).colorScheme.primary,
145 size: 25.sp,
146 ),
147 ),
148 ),
149 ),
150 ),
151 ),
152 ],
153 ),
154 ),
155 );
156 }
157}
final VideoEntity video
const VideoCard({ super.key, required this.video, })
override State< VideoCard > createState()
const CustomCard({ super.key, required this.child, this.padding, this.bgColor, })
final Widget child
final EdgeInsets padding
final Color backgroundColor
final Color color
Definition failures.dart:1
override Widget build(BuildContext context)
const VideoCard({ super.key, required this.video, })
class VideoCard extends StatefulWidget opslaunchVideo(String videoUrl)
String getYoutubeThumbnail(String videoUrl)