Ad
How To Support HTTP Headers NetworkImage In Flutter Web
I tried to get some images from the internet in flutter web that need to add headers.
I've used cached_network_image: ^2.5.1 and it doesn't support the web completely also Image.network seems when running flutter on the web, headers are not used. Both of these ways successfully work on the Android release.
environment:
sdk: ">=2.7.0 <3.0.0"
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.4, on Microsoft Windows [Version 10.0.19042.985], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] IntelliJ IDEA Ultimate Edition (version 2020.1)
[√] Connected device (3 available)
• No issues found!
Ad
Answer
With cached_network_image: 3.0.0 I got it working to add headers by using the CachedNetworkImageProvider class.
CachedNetworkImageProvider(
"${IOConfig.apiUrl}",
headers: {"Authorization": "Bearer $apiToken",
"Access-Control-Allow-Headers": "Access-Control-Allow-Origin, Accept"}
,imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet)
I had to start it with an argument to change the web-renderer
flutter run -d chrome --web-renderer html
Ad
source: stackoverflow.com
Related Questions
- → How do you create a 12 or 24 mnemonics code for multiple cryptocurrencies (ETH, BTC and so on..)
- → Flutter: input text field don't work properly in a simple example..... where am I wrong?
- → Can I customize the code formatting of Dart code in Atom?
- → Is it possible to develop iOS apps with Flutter on a Linux virtual machine?
- → Display SnackBar in Flutter
- → JSON ObjectMapper in Flutter
- → Material flutter app source code
- → TabBarSelection No such method error
- → How do I set the animation color of a LinearProgressIndicator?
- → Add different routes/screens to Flutter app
- → Is there a way to get the size of an existing widget?
- → How to share a file using flutter
- → Is there an easy way to find particular text built from RichText in a Flutter test?
Ad