feat(ui): Cache tracked cover images for offline use

This commit is contained in:
2023-02-06 16:53:48 +01:00
parent 6a5c970101
commit 67531b84f0
6 changed files with 164 additions and 3 deletions

View File

@@ -101,7 +101,7 @@ class AnimeListPage extends StatelessWidget {
body: PageView(
// Prevent swiping between pages
// (https://github.com/flutter/flutter/issues/37510#issuecomment-612663656)
physics: NeverScrollableScrollPhysics(),
physics: const NeverScrollableScrollPhysics(),
controller: _controller,
children: [
ListView.builder(

View File

@@ -72,6 +72,7 @@ class AnimeSearchPage extends StatelessWidget {
child: ListItem(
title: item.title,
thumbnailUrl: item.thumbnailUrl,
cached: false,
extra: [
Align(
alignment: Alignment.centerLeft,

View File

@@ -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,
),
),

View File

@@ -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,
),