feat(ui): Cache tracked cover images for offline use
This commit is contained in:
@@ -1,14 +1,19 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AnimeCoverImage extends StatelessWidget {
|
||||
const AnimeCoverImage({
|
||||
required this.url,
|
||||
this.cached = true,
|
||||
super.key,
|
||||
});
|
||||
|
||||
/// The URL to the cover image.
|
||||
final String url;
|
||||
|
||||
/// Flag indicating if the image should be cached
|
||||
final bool cached;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ClipRRect(
|
||||
@@ -19,7 +24,9 @@ class AnimeCoverImage extends StatelessWidget {
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: NetworkImage(url),
|
||||
image: cached ?
|
||||
CachedNetworkImageProvider(url) as ImageProvider :
|
||||
NetworkImage(url),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -10,6 +10,7 @@ class ListItem extends StatelessWidget {
|
||||
required this.title,
|
||||
this.onLeftSwipe,
|
||||
this.onRightSwipe,
|
||||
this.cached = true,
|
||||
this.extra = const [],
|
||||
super.key,
|
||||
});
|
||||
@@ -27,6 +28,9 @@ class ListItem extends StatelessWidget {
|
||||
final void Function()? onLeftSwipe;
|
||||
final void Function()? onRightSwipe;
|
||||
|
||||
/// Flag indicating whether the thumbnail image should be cached
|
||||
final bool cached;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SwipeableTile.swipeToTrigger(
|
||||
@@ -68,6 +72,7 @@ class ListItem extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AnimeCoverImage(
|
||||
cached: cached,
|
||||
url: thumbnailUrl,
|
||||
),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user