2022-08-06 16:46:31 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-06 14:05:14 +00:00
|
|
|
import 'package:localization/localization.dart';
|
2022-08-06 14:50:30 +00:00
|
|
|
import 'package:loris/business_logic/timeline/media.dart';
|
2022-08-06 14:05:14 +00:00
|
|
|
|
|
|
|
class MediaAttachments extends StatelessWidget {
|
|
|
|
const MediaAttachments({required this.models, Key? key}) : super(key: key);
|
|
|
|
final List<MediaAttachmentModel> models;
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
List<Widget> children = [];
|
|
|
|
for (int i = 0; i < models.length; i++) {
|
2022-08-10 18:49:51 +00:00
|
|
|
if (models[i].type == "image" || models[i].type == "gif") {
|
2022-08-06 14:05:14 +00:00
|
|
|
children.add(ImageAttachmentDisplay(model: models[i]));
|
|
|
|
} else {
|
|
|
|
children.add(Text("media-not-supported".i18n()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: children,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ImageAttachmentDisplay extends StatelessWidget {
|
|
|
|
const ImageAttachmentDisplay({required this.model, Key? key})
|
|
|
|
: super(key: key);
|
|
|
|
final MediaAttachmentModel model;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-06 16:46:31 +00:00
|
|
|
return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
2022-08-10 16:47:34 +00:00
|
|
|
Image.network(
|
|
|
|
model.url,
|
2022-08-10 18:49:51 +00:00
|
|
|
errorBuilder: ((context, error, stackTrace) => const Icon(Icons.error)),
|
2022-08-10 16:47:34 +00:00
|
|
|
width: double.infinity,
|
|
|
|
fit: BoxFit.fitWidth,
|
|
|
|
),
|
2022-08-12 22:28:00 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 4,
|
|
|
|
),
|
2022-08-06 16:46:31 +00:00
|
|
|
AltText(text: model.description.toString())
|
2022-08-06 14:05:14 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2022-08-06 16:46:31 +00:00
|
|
|
|
|
|
|
class AltText extends StatelessWidget {
|
|
|
|
const AltText({
|
|
|
|
required this.text,
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
final String text;
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SelectableText(
|
|
|
|
text,
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|