Files
feeddeck/app/lib/widgets/item/details/item_details_rss.dart
Rico Berger 55c6da07d9 [rss] Improve Rendering of Items (#52)
The items of an RSS feed are now rendered better, to achieve this we did
the following changes:

- Remove leading and trailing whitespaces from the item description
  which should be rendered.
- Check if the media file of an item is an SVG image. If this is the
  case we will not add it to the "media" field in the database, because
  currently the CachedNetworkImage widget can not render SVGs. If we
  want to render them, we run into serious performance issue so we skip
  them completly.
- Always assume that the content of an RSS feed contains HTML and render
  them as plain text in the preview and as markdown in the details.
  Since we also render images from the description now, we check if the
  "item.media" image should be rendered. If the description contains an
  image we do not render our own image. If the description doesn't
  contain a image we render it.
2023-10-28 11:37:00 +02:00

63 lines
1.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:html/parser.dart' show parse;
import 'package:feeddeck/models/item.dart';
import 'package:feeddeck/models/source.dart';
import 'package:feeddeck/widgets/item/details/utils/item_description.dart';
import 'package:feeddeck/widgets/item/details/utils/item_media.dart';
import 'package:feeddeck/widgets/item/details/utils/item_subtitle.dart';
import 'package:feeddeck/widgets/item/details/utils/item_title.dart';
class ItemDetailsRSS extends StatelessWidget {
const ItemDetailsRSS({
super.key,
required this.item,
required this.source,
});
final FDItem item;
final FDSource source;
/// [_buildImage] renders the [item.media] when the [shouldBeRendered] is
/// `true`. If it is `false` an empty container is returned.
Widget _buildImage(bool shouldBeRendered) {
if (!shouldBeRendered) {
return Container();
}
return ItemMedia(
itemMedia: item.media,
);
}
@override
Widget build(BuildContext context) {
/// Check if the description of the RSS feed contains an image. If this is
/// the case we do not render the image from the [item.media] because the
/// image is already rendered in the [ItemDescription] widget.
final descriptionContainImage =
parse(item.description).querySelectorAll('img').isNotEmpty;
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.start,
children: [
ItemTitle(
itemTitle: item.title,
),
ItemSubtitle(
item: item,
source: source,
),
_buildImage(!descriptionContainImage),
ItemDescription(
itemDescription: item.description,
sourceFormat: DescriptionFormat.html,
tagetFormat: DescriptionFormat.markdown,
),
],
);
}
}