46 lines
1.5 KiB
Dart
46 lines
1.5 KiB
Dart
import 'dart:convert';
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:sendtrain/database/database.dart';
|
|
import 'package:sendtrain/helpers/widget_helpers.dart';
|
|
|
|
class MediaCard extends StatelessWidget {
|
|
const MediaCard({super.key, required this.media});
|
|
|
|
final MediaItem media;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
DecorationImage mediaImage(MediaItem media) {
|
|
dynamic image;
|
|
|
|
if (media.type == MediaType.image || media.type == MediaType.location) {
|
|
image = NetworkImage(media.reference);
|
|
} else if (media.type == MediaType.localImage) {
|
|
image = Image.memory(base64Decode(media.reference)).image;
|
|
} else if (media.type == MediaType.youtube) {
|
|
image = NetworkImage('https://img.youtube.com/vi/${media.reference}/0.jpg');
|
|
}
|
|
|
|
return DecorationImage(image: image, fit: BoxFit.cover);
|
|
}
|
|
|
|
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: () => showMediaDetailWidget(context, media),
|
|
child: const ListTile(
|
|
title: Text(''),
|
|
))));
|
|
}
|
|
}
|