-
-
Notifications
You must be signed in to change notification settings - Fork 654
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
Is there any way to pass a HttpClient instance? #649
Comments
I really would like to know this, too. I think it is kind of an essential feature. But it looks like a http-session is created for every single image (#555). That would be absolutely horrible π |
I'll take you around the CacheManager files. When creating the CacheManager you supply a config file in the constructor. The default IO config file uses a standard HttpFileService if nothing else is provided. That http fileservice only creates 1 http client if no other client is provided. So what you can do is create a different CacheManager object that you supply a config with an HttpFileService that has your httpclient. At the moment you cannot configure this per request. So like this:
|
i'm sorry, i'm still not quite sure what you meant and where to apply said code. is it in main.dart? or do i have to manually fork the plugin? i'm using self signed certificate on my client so i need to pass the httpClient to the plugin so it can retrieve it successfully, instead of handshake certificate expired. ``the code httpClient = IOClient(HttpClient(context: clientContext)); |
and i'm stoopid bakka......
|
Just a piece of copypasteable code: import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:http/http.dart' as http;
final cacheManager = CacheManager(
Config(
'cacheKey',
fileService: HttpFileService(
httpClient: http.Client(),
),
),
); If using it as If you think it's a good way to deal with it, thanks a lot and feel free to close the issue π |
how does cached_network_image know which CacheManager it should use? |
OK, seems like you have to pass the CacheManager to every CachedNetworkImage as paramter |
If you want to use the cronet or cupertino clients, they cannot be used with My question is: is it inefficient to reinstantiate a new |
@renefloor said:
but |
If you don't want to deal with context, you can use get_it instead of Provider there.
We use cache_network_image and pass the cache_mamager via get_it without problems.
BTW runWithClient works most of the time for us. We only saw that JNI exception once so far.
Am 27. Juni 2024, 23:16 +0100 schrieb Luke Hutchison ***@***.***>:
β¦ If you want to use the cronet or cupertino clients, they cannot be used with runWithClient, and to use the suggested solution of using Provider<Client>, you would have to pass in a new CacheManager instance every time you use CacheWithNetworkImage (because you have to get the Client implementation from the BuildContext, using context.read<Client>).
My question is: is it inefficient to reinstantiate a new CacheManager and a new HttpFileService for every new CachedNetworkImage request? Or as long as the 'cacheKey' matches every time, is the cache going to be reused between requests?
β
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Why would you want to do this on every request?
Am 27. Juni 2024, 23:20 +0100 schrieb Luke Hutchison ***@***.***>:
β¦ @renefloor said:
> So what you can do is create a different CacheManager object that you supply a config with an HttpFileService that has your httpclient. At the moment you cannot configure this per request.
but CachedNetworkImage does take a cacheManager parameter, so why can this not be configured per request?
β
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Because see these comments re context: dart-lang/http#1241 (comment) I don't think you can just rely on getting the |
@escamoteur can you please provide full example code of what you are doing? Why do you need to use |
Sure, that is exactly what I do, I register one Client and one Cache Manager in get_it and then I use them everywhere.
I will write a blog post about this in the next days
Am 28. Juni 2024, 00:05 +0100 schrieb Luke Hutchison ***@***.***>:
β¦ > Why would you want to do this on every request?
Because see these comments re context: dart-lang/http#1241 (comment)
I don't think you can just rely on getting the Client instance once, and then pre-creating a single instance of cacheManager. But I don't fully understand the context issue.
β
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Can I see how you're setting up the |
Not at my computer at the moment. Do you get that exception all the time?
Am 28. Juni 2024, 00:13 +0100 schrieb Hossein Yousefi ***@***.***>:
β¦ > We only saw that JNI exception once so far.
Can I see how you're setting up the runWithClient?
β
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I don't think we should be getting the exception to begin with! I'm maintaining |
I just read a comment of one of our users who said since we added cronnet the app doesn't start anymore. He mentioned that he uses an Android without play services. My hunch is that cronnet might not be available on such systems. Will try tomorrow
Am 28. Juni 2024, 00:18 +0100 schrieb Hossein Yousefi ***@***.***>:
β¦ I don't think we should be getting the exception to begin with! I'm maintaining package:jni which is a dependency of package:cronet_http and I want to know why this happens.
β
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@escamoteur No worries. Btw are you coming tomorrow to the GDE conf in Berlin? I have a talk there, we can meet and talk about it there! |
Unfortunately not, I m on Tenerife over the summer working from here.
Am 28. Juni 2024, 00:21 +0100 schrieb Hossein Yousefi ***@***.***>:
β¦ @escamoteur No worries. Btw are you coming tomorrow to the GDE conf in Berlin? I have a talk there, we can meet and talk about it there!
β
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@escamoteur was that when you were using |
ok, I could just reproduce this, it has nothing to do with |
What is the exact failure, and is there a way to detect that this is going to fail? I want to make my app robust to this situation... Also, why on earth would cronet require Google Play Services? It is just the Chromium HTTP client library... @HosseinYousefi |
check dart-lang/http#1241 (comment) I agreee, I too I'm surprised that it seems that cronnet is part of the Google play service part of Android |
Hello! π
As we try to use the same
HttpClient
to keep keepalive connections, is there any way to pass theCachedNetworkImageProvider
aHttpClient
to use?Thanks πββοΈ
The text was updated successfully, but these errors were encountered: