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

This commit is contained in:
PapaTutuWawa 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,
),

View File

@ -113,6 +113,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "8.4.3"
cached_network_image:
dependency: "direct main"
description:
name: cached_network_image
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.3"
cached_network_image_platform_interface:
dependency: transitive
description:
name: cached_network_image_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
cached_network_image_web:
dependency: transitive
description:
name: cached_network_image_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
characters:
dependency: transitive
description:
@ -190,6 +211,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
file:
dependency: transitive
description:
@ -216,6 +244,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "8.1.1"
flutter_blurhash:
dependency: transitive
description:
name: flutter_blurhash
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.0"
flutter_cache_manager:
dependency: transitive
description:
name: flutter_cache_manager
url: "https://pub.dartlang.org"
source: hosted
version: "3.3.0"
flutter_launcher_icons:
dependency: "direct dev"
description:
@ -389,6 +431,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
octo_image:
dependency: transitive
description:
name: octo_image
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
package_config:
dependency: transitive
description:
@ -403,6 +452,55 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
path_provider:
dependency: transitive
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.12"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.22"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.7"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.1"
petitparser:
dependency: transitive
description:
@ -410,6 +508,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.0"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
pointycastle:
dependency: transitive
description:
@ -424,6 +536,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.1"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.4"
provider:
dependency: transitive
description:
@ -445,6 +564,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
rxdart:
dependency: transitive
description:
name: rxdart
url: "https://pub.dartlang.org"
source: hosted
version: "0.27.7"
shelf:
dependency: transitive
description:
@ -569,6 +695,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
uuid:
dependency: transitive
description:
name: uuid
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.7"
vector_math:
dependency: transitive
description:
@ -597,6 +730,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0+3"
xml:
dependency: transitive
description:

View File

@ -9,7 +9,8 @@ environment:
dependencies:
bloc: ^8.1.0
bottom_bar: ^2.0.3
bottom_bar: ^2.0.3
cached_network_image: ^3.2.3
cupertino_icons: ^1.0.2
flutter:
sdk: flutter