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( body: PageView(
// Prevent swiping between pages // Prevent swiping between pages
// (https://github.com/flutter/flutter/issues/37510#issuecomment-612663656) // (https://github.com/flutter/flutter/issues/37510#issuecomment-612663656)
physics: NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
controller: _controller, controller: _controller,
children: [ children: [
ListView.builder( ListView.builder(

View File

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

View File

@ -1,14 +1,19 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class AnimeCoverImage extends StatelessWidget { class AnimeCoverImage extends StatelessWidget {
const AnimeCoverImage({ const AnimeCoverImage({
required this.url, required this.url,
this.cached = true,
super.key, super.key,
}); });
/// The URL to the cover image. /// The URL to the cover image.
final String url; final String url;
/// Flag indicating if the image should be cached
final bool cached;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ClipRRect( return ClipRRect(
@ -19,7 +24,9 @@ class AnimeCoverImage extends StatelessWidget {
child: DecoratedBox( child: DecoratedBox(
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: NetworkImage(url), image: cached ?
CachedNetworkImageProvider(url) as ImageProvider :
NetworkImage(url),
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),

View File

@ -10,6 +10,7 @@ class ListItem extends StatelessWidget {
required this.title, required this.title,
this.onLeftSwipe, this.onLeftSwipe,
this.onRightSwipe, this.onRightSwipe,
this.cached = true,
this.extra = const [], this.extra = const [],
super.key, super.key,
}); });
@ -27,6 +28,9 @@ class ListItem extends StatelessWidget {
final void Function()? onLeftSwipe; final void Function()? onLeftSwipe;
final void Function()? onRightSwipe; final void Function()? onRightSwipe;
/// Flag indicating whether the thumbnail image should be cached
final bool cached;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SwipeableTile.swipeToTrigger( return SwipeableTile.swipeToTrigger(
@ -68,6 +72,7 @@ class ListItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
AnimeCoverImage( AnimeCoverImage(
cached: cached,
url: thumbnailUrl, url: thumbnailUrl,
), ),

View File

@ -113,6 +113,27 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "8.4.3" 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: characters:
dependency: transitive dependency: transitive
description: description:
@ -190,6 +211,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
file: file:
dependency: transitive dependency: transitive
description: description:
@ -216,6 +244,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "8.1.1" 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: flutter_launcher_icons:
dependency: "direct dev" dependency: "direct dev"
description: description:
@ -389,6 +431,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.0" 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: package_config:
dependency: transitive dependency: transitive
description: description:
@ -403,6 +452,55 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.2" 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: petitparser:
dependency: transitive dependency: transitive
description: description:
@ -410,6 +508,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.1.0" 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: pointycastle:
dependency: transitive dependency: transitive
description: description:
@ -424,6 +536,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.5.1" version: "1.5.1"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.4"
provider: provider:
dependency: transitive dependency: transitive
description: description:
@ -445,6 +564,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.1" version: "1.2.1"
rxdart:
dependency: transitive
description:
name: rxdart
url: "https://pub.dartlang.org"
source: hosted
version: "0.27.7"
shelf: shelf:
dependency: transitive dependency: transitive
description: description:
@ -569,6 +695,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
uuid:
dependency: transitive
description:
name: uuid
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.7"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
@ -597,6 +730,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.3.0" 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: xml:
dependency: transitive dependency: transitive
description: description:

View File

@ -9,7 +9,8 @@ environment:
dependencies: dependencies:
bloc: ^8.1.0 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 cupertino_icons: ^1.0.2
flutter: flutter:
sdk: flutter sdk: flutter