Skip to content

Commit

Permalink
Cache images to save bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
creeperkafasi committed Oct 16, 2023
1 parent 8b68bd9 commit 699ede2
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 13 deletions.
10 changes: 7 additions & 3 deletions lib/home.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:miteru/search.dart';
import 'package:miteru/show.dart';
Expand Down Expand Up @@ -126,7 +127,8 @@ class _HomePageState extends State<HomePage> {
ClipRRect(
borderRadius:
BorderRadius.circular(8.0),
child: Image.network(
child: CachedNetworkImage(
imageUrl:
e["anyCard"]["thumbnail"],
height: 130,
),
Expand Down Expand Up @@ -180,7 +182,8 @@ class _HomePageState extends State<HomePage> {
ClipRRect(
borderRadius:
BorderRadius.circular(8.0),
child: Image.network(
child: CachedNetworkImage(
imageUrl:
e["thumbnail"],
height: 130,
),
Expand Down Expand Up @@ -304,7 +307,8 @@ class _HomePageState extends State<HomePage> {
children: [
ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: Image.network(
child: CachedNetworkImage(
imageUrl:
snapshot.data!["data"]["attributes"]["posterImage"]
["tiny"] ??
"https://placehold.co/90x130/png?text=?",
Expand Down
13 changes: 7 additions & 6 deletions lib/search.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/foundation.dart';
import 'package:miteru/show.dart';
import 'package:flutter/material.dart';
import 'package:miteru/utils/allanime.dart';
import 'package:miteru/utils/db.dart';

class AnimeSearchDelegate extends SearchDelegate {

@override
List<Widget>? buildActions(BuildContext context) {
return [
Expand Down Expand Up @@ -77,15 +77,16 @@ class AnimeSearchDelegate extends SearchDelegate {
children: [
Padding(
padding: const EdgeInsets.all(4.0),
child: Image.network(
items[index]["thumbnail"] ??
child: CachedNetworkImage(
imageUrl: items[index]["thumbnail"] ??
"https://placehold.co/64x108/png?text=?",
height: 108,
width: 64,
fit: BoxFit.contain,
errorBuilder: (context, error, stackTrace) =>
Image.network(
"https://placehold.co/64x108/png?text=?"),
errorWidget: (context, error, stackTrace) =>
CachedNetworkImage(
imageUrl: "https://placehold.co/64x108/png?text=?",
),
),
),
Expanded(
Expand Down
12 changes: 8 additions & 4 deletions lib/show.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:ui';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:miteru/utils/allanime.dart';
import 'package:miteru/watch.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -58,10 +59,12 @@ class _ShowOverviewState extends State<ShowOverview> {
Rect.fromLTRB(0, 0, rect.width, rect.height));
},
blendMode: BlendMode.dstIn,
child: Image.network(
child: CachedNetworkImage(
imageUrl:
showInfo["banner"],
errorBuilder: (context, error, stackTrace) =>
Image.network(
errorWidget: (context, error, stackTrace) =>
CachedNetworkImage(
imageUrl:
"https://placehold.co/64x108/png?text=?",
),
),
Expand All @@ -83,7 +86,8 @@ class _ShowOverviewState extends State<ShowOverview> {
),
elevation: 8,
clipBehavior: Clip.antiAlias,
child: Image.network(
child: CachedNetworkImage(
imageUrl:
showInfo["thumbnail"],
height: 180,
),
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Foundation
import fvp
import path_provider_foundation
import shared_preferences_foundation
import sqflite
import sqlite3_flutter_libs
import url_launcher_macos
import video_player_avfoundation
Expand All @@ -17,6 +18,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FvpPlugin.register(with: registry.registrar(forPlugin: "FvpPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
Expand Down
72 changes: 72 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.1"
cached_network_image:
dependency: "direct main"
description:
name: cached_network_image
sha256: f98972704692ba679db144261172a8e20feb145636c617af0eb4022132a6797f
url: "https://pub.dev"
source: hosted
version: "3.3.0"
cached_network_image_platform_interface:
dependency: transitive
description:
name: cached_network_image_platform_interface
sha256: "56aa42a7a01e3c9db8456d9f3f999931f1e05535b5a424271e9a38cabf066613"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
cached_network_image_web:
dependency: transitive
description:
name: cached_network_image_web
sha256: "759b9a9f8f6ccbb66c185df805fac107f05730b1dab9c64626d1008cca532257"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -150,6 +174,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_cache_manager:
dependency: transitive
description:
name: flutter_cache_manager
sha256: "8207f27539deb83732fdda03e259349046a39a4c767269285f449ade355d54ba"
url: "https://pub.dev"
source: hosted
version: "3.3.1"
flutter_launcher_icons:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -288,6 +320,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.0"
octo_image:
dependency: transitive
description:
name: octo_image
sha256: "45b40f99622f11901238e18d48f5f12ea36426d8eced9f4cbf58479c7aa2430d"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -384,6 +424,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "6.0.5"
rxdart:
dependency: transitive
description:
name: rxdart
sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb"
url: "https://pub.dev"
source: hosted
version: "0.27.7"
shared_preferences:
dependency: "direct main"
description:
Expand Down Expand Up @@ -453,6 +501,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.10.0"
sprintf:
dependency: transitive
description:
name: sprintf
sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
sqflite:
dependency: transitive
description:
name: sqflite
sha256: "591f1602816e9c31377d5f008c2d9ef7b8aca8941c3f89cc5fd9d84da0c38a9a"
url: "https://pub.dev"
source: hosted
version: "2.3.0"
sqflite_common:
dependency: transitive
description:
Expand Down Expand Up @@ -613,6 +677,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.8"
uuid:
dependency: transitive
description:
name: uuid
sha256: b715b8d3858b6fa9f68f87d20d98830283628014750c2b09b6f516c1da4af2a7
url: "https://pub.dev"
source: hosted
version: "4.1.0"
vector_math:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies:
fvp: ^0.8.0
m3u_nullsafe: ^1.0.4
url_launcher: ^6.1.14
cached_network_image: ^3.3.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 699ede2

Please sign in to comment.