Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to stop dowload image? #26

Open
bakboem opened this issue Jun 15, 2023 · 2 comments
Open

How to stop dowload image? #26

bakboem opened this issue Jun 15, 2023 · 2 comments
Labels
feature required Need a new feature

Comments

@bakboem
Copy link

bakboem commented Jun 15, 2023

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/ddc_runtime/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).

@ghost ghost added the feature required Need a new feature label Jul 14, 2023
@aniljailta
Copy link

@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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature required Need a new feature
Projects
None yet
Development

No branches or pull requests

3 participants