loris/lib/partials/media_attachment.dart

69 lines
1.9 KiB
Dart
Raw Normal View History

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';
import 'package:loris/business_logic/timeline/media.dart';
import 'package:url_launcher/url_launcher_string.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(TextButton.icon(
onPressed: () {
launchUrlString(models[i].url);
},
icon: const Icon(Icons.open_in_browser),
label: Text("open-media-in-browser".i18n())));
2022-08-06 14:05:14 +00:00
}
}
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-26 22:29:36 +00:00
model.description == null
? const SizedBox()
: AltText(text: model.description!),
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,
);
}
}