94 lines
3.5 KiB
Dart
94 lines
3.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:sendtrain/database/database.dart';
|
|
import 'package:youtube_player_flutter/youtube_player_flutter.dart';
|
|
|
|
class MediaCard extends StatelessWidget {
|
|
const MediaCard({super.key, required this.media});
|
|
|
|
final MediaItem media;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
YoutubePlayerController controller = YoutubePlayerController(
|
|
initialVideoId: media.reference,
|
|
flags: const YoutubePlayerFlags(
|
|
autoPlay: false, mute: true, showLiveFullscreenButton: false));
|
|
|
|
DecorationImage mediaImage(MediaItem media) {
|
|
String image = '';
|
|
|
|
if (media.type == MediaType.image) {
|
|
image = media.reference;
|
|
} else if (media.type == MediaType.youtube) {
|
|
image = 'https://img.youtube.com/vi/${media.reference}/0.jpg';
|
|
}
|
|
|
|
return DecorationImage(image: NetworkImage(image), fit: BoxFit.cover);
|
|
}
|
|
|
|
Widget mediaItem(MediaItem media) {
|
|
if (media.type == MediaType.image) {
|
|
return Image(image: NetworkImage(media.reference));
|
|
} else if (media.type == MediaType.youtube) {
|
|
return YoutubePlayer(
|
|
controller: controller,
|
|
aspectRatio: 16 / 9,
|
|
);
|
|
}
|
|
|
|
return const Image(image: AssetImage('assets/images/placeholder.jpg'));
|
|
}
|
|
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(10),
|
|
image: mediaImage(media),
|
|
),
|
|
child: Card(
|
|
color: Colors.transparent,
|
|
shape:
|
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
|
shadowColor: const Color.fromARGB(0, 255, 255, 255),
|
|
child: TextButton(
|
|
onPressed: () => showModalBottomSheet<void>(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(10.0)),
|
|
),
|
|
context: context,
|
|
showDragHandle: true,
|
|
isScrollControlled: true,
|
|
useSafeArea: true,
|
|
builder: (BuildContext context) {
|
|
return Padding(
|
|
padding: EdgeInsets.fromLTRB(15, 0, 15, 15),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: <Widget>[
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(10),
|
|
child: mediaItem(media),
|
|
),
|
|
const SizedBox(height: 15),
|
|
Padding(
|
|
padding: EdgeInsets.fromLTRB(15, 0, 15, 15),
|
|
child: Text(
|
|
media.description,
|
|
style: const TextStyle(fontSize: 20),
|
|
)),
|
|
const Divider(
|
|
indent: 20,
|
|
endIndent: 20,
|
|
)
|
|
]));
|
|
// const Text(
|
|
// 'Comments',
|
|
// style: TextStyle(fontSize: 20),
|
|
// ),
|
|
}),
|
|
child: const ListTile(
|
|
title: Text(''),
|
|
))));
|
|
}
|
|
}
|