Skip to content

Commit

Permalink
implemented cached network image
Browse files Browse the repository at this point in the history
  • Loading branch information
klortiz13 committed Sep 14, 2024
1 parent 1eb5dcc commit f13f384
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
24 changes: 9 additions & 15 deletions lib/ui/common/image_loader.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

class ImageLoader extends StatelessWidget {
final String? url;
Expand All @@ -17,23 +18,16 @@ class ImageLoader extends StatelessWidget {
width: 0,
height: 0,
)
: Image.network(
url!,
: CachedNetworkImage(
imageUrl: url!,
width: fullSize ? null : width,
height: fullSize ? null : height,
loadingBuilder: (BuildContext context, Widget child,
ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: CircularProgressIndicator(
color: Theme.of(context).colorScheme.secondary,
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
),
);
},
placeholder: (context, url) => Center(
child: CircularProgressIndicator(
color: Theme.of(context).colorScheme.secondary,
),
),
errorWidget: (context, url, error) => Icon(Icons.error),
);
}
}
40 changes: 40 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "8.6.1"
cached_network_image:
dependency: "direct main"
description:
name: cached_network_image
sha256: fd3d0dc1d451f9a252b32d95d3f0c3c487bc41a75eba2e6097cb0b9c71491b15
url: "https://pub.dev"
source: hosted
version: "3.2.3"
cached_network_image_platform_interface:
dependency: transitive
description:
name: cached_network_image_platform_interface
sha256: bb2b8403b4ccdc60ef5f25c70dead1f3d32d24b9d6117cfc087f496b178594a7
url: "https://pub.dev"
source: hosted
version: "2.0.0"
cached_network_image_web:
dependency: transitive
description:
name: cached_network_image_web
sha256: b8eb814ebfcb4dea049680f8c1ffb2df399e4d03bf7a352c775e26fa06e02fa0
url: "https://pub.dev"
source: hosted
version: "1.0.2"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -446,6 +470,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_blurhash:
dependency: transitive
description:
name: flutter_blurhash
sha256: "05001537bd3fac7644fa6558b09ec8c0a3f2eba78c0765f88912882b1331a5c6"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
flutter_cache_manager:
dependency: transitive
description:
Expand Down Expand Up @@ -867,6 +899,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.0"
octo_image:
dependency: transitive
description:
name: octo_image
sha256: "107f3ed1330006a3bea63615e81cf637433f5135a52466c7caa0e7152bca9143"
url: "https://pub.dev"
source: hosted
version: "1.0.2"
package_config:
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 @@ -55,6 +55,7 @@ dependencies:
just_audio: ^0.9.31
just_audio_background: ^0.0.1-beta.9
device_info_plus: ^9.1.2
cached_network_image: ^3.2.3
dev_dependencies:
build_runner: 2.0.2
flutter_test:
Expand Down

0 comments on commit f13f384

Please sign in to comment.