CHRISTOPANANJICKAL / fast_cached_network_image

A flutter package to cache network image fastly without native dependencies.
MIT License
29 stars 35 forks source link

How to stop dowload image? #26

Open bakboem opened 1 year ago

bakboem commented 1 year ago

When I nest the Gridview with ExpantionTitle and use this plugin to cache network images in the item body, (default off) when Expantion is opened/closed quickly, it will fail to dispose. I hope there is a way to stop the download. thanks!~

Error: This widget has been unmounted, so the State no longer has a context (and should be considered defunct). Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active. ../dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 288:49 throw ../packages/flutter/src/widgets/framework.dart 951:9 ../packages/flutter/src/widgets/framework.dart 956:14 get context ../packages/fast_cached_network_image/src/fast_cached_image.dart 315:34 ../packages/dio/src/adapters/browser_adapter.dart 133:18 ../dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 367:37 _checkAndCall ../dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 372:39 dcall ../dart-sdk/lib/html/dart2js/html_dart2js.dart 37236:58 Error: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).

aniljailta commented 7 months ago

@bakboem import 'package:fast_cached_network_image/fast_cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:makefitsimple/config/color.dart';

import '../../config/image.dart';

class CachedImage extends StatefulWidget { final String imageUrl; final double? width; final double? height; const CachedImage( {super.key, required this.imageUrl, this.width, this.height});

@override State createState() => _CachedImageState(); }

class _CachedImageState extends State { bool _mounted = false;

@override void initState() { super.initState(); _mounted = true; }

@override void dispose() { _mounted = false; super.dispose(); }

@override Widget build(BuildContext context) { return FastCachedImage( key: ValueKey(widget.imageUrl + DateTime.now().day.toString()), width: widget.width ?? double.infinity, height: widget.height ?? double.infinity, url: widget.imageUrl, fit: BoxFit.cover, fadeInDuration: const Duration(seconds: 1), errorBuilder: (context, exception, stacktrace) { return Image.asset( AppImage.andreaHorizon, fit: BoxFit.cover, width: widget.width ?? double.infinity, height: widget.height ?? double.infinity, ); }, loadingBuilder: _mounted ? null : (context, progress) { return Padding( padding: const EdgeInsets.all(100), child: CircularProgressIndicator( value: progress.progressPercentage.value, color: AppColor.primaryColor, ), ); }, ); } } This is what I did to stop the app from crashing or throwing exception

CHRISTOPANANJICKAL commented 7 months ago

This feature will be added in a future update. waiting for some packages to provide web support so that we can use them.