media item and session images and location management, also refactoring and DRYing up code
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sendtrain/database/database.dart';
|
||||
import 'package:youtube_player_flutter/youtube_player_flutter.dart';
|
||||
import 'package:sendtrain/helpers/widget_helpers.dart';
|
||||
|
||||
class MediaCard extends StatelessWidget {
|
||||
const MediaCard({super.key, required this.media});
|
||||
@ -9,15 +9,10 @@ class MediaCard extends StatelessWidget {
|
||||
|
||||
@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) {
|
||||
if (media.type == MediaType.image || media.type == MediaType.location) {
|
||||
image = media.reference;
|
||||
} else if (media.type == MediaType.youtube) {
|
||||
image = 'https://img.youtube.com/vi/${media.reference}/0.jpg';
|
||||
@ -26,19 +21,6 @@ class MediaCard extends StatelessWidget {
|
||||
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),
|
||||
@ -50,42 +32,7 @@ class MediaCard extends StatelessWidget {
|
||||
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),
|
||||
// ),
|
||||
}),
|
||||
onPressed: () => showMediaDetailWidget(context, media),
|
||||
child: const ListTile(
|
||||
title: Text(''),
|
||||
))));
|
||||
|
28
lib/widgets/media/media_content.dart
Normal file
28
lib/widgets/media/media_content.dart
Normal file
@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sendtrain/database/database.dart';
|
||||
import 'package:youtube_player_flutter/youtube_player_flutter.dart';
|
||||
|
||||
class MediaContent extends StatelessWidget {
|
||||
const MediaContent({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));
|
||||
|
||||
if (media.type == MediaType.image || media.type == MediaType.location) {
|
||||
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'));
|
||||
}
|
||||
}
|
35
lib/widgets/media/media_details.dart
Normal file
35
lib/widgets/media/media_details.dart
Normal file
@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sendtrain/database/database.dart';
|
||||
import 'package:sendtrain/widgets/media/media_content.dart';
|
||||
|
||||
class MediaDetails extends StatelessWidget {
|
||||
const MediaDetails({super.key, required this.media});
|
||||
|
||||
final MediaItem media;
|
||||
|
||||
@override
|
||||
Widget build(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: MediaContent(media: 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,
|
||||
)
|
||||
]));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user