Here is my code for get image:
Image.network('http://10.0.2.2:8000/${widget.product.imageUrl}', fit: BoxFit.cover),
and the error:
════════ Exception caught by image resource service ════════════════════════════
The following HttpException was thrown resolving an image codec:
Connection closed while receiving data, uri = http://10.0.2.2:8000/uploads/products/0-1713659504.png
When the exception was thrown, this was the stack:
#0 _HttpIncoming.listen.<anonymous closure> (dart:_http/http_impl.dart:442:7)
http_impl.dart:442
#11 _HttpParser._reportBodyError (dart:_http/http_parser.dart:1201:22)
http_parser.dart:1201
#12 _HttpParser._onDone (dart:_http/http_parser.dart:899:9)
http_parser.dart:899
#20 _Socket._onData (dart:io-patch/socket_patch.dart:2454:21)
socket_patch.dart:2454
#27 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1943:35)
socket_patch.dart:1943
#28 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1372:18)
socket_patch.dart:1372
(elided 25 frames from dart:async)
Image provider: NetworkImage("http://10.0.2.2:8000/uploads/products/0-1713659504.png", scale: 1.0)
Image key: NetworkImage("http://10.0.2.2:8000/uploads/products/0-1713659504.png", scale: 1.0)
I tried to use this but didn’t work:
CachedNetworkImage(imageUrl: 'http://10.0.2.2:8000/${image['image']}', placeholder: (context, url) => CircularProgressIndicator(), // Tampilkan indicator loading errorWidget: (context, url, error) => Icon(Icons.error), ),
and this
Another exception was thrown: HttpException: Connection closed while receiving data, uri =
but still didn’t work.
How can it be fixed to do this?
2
Answers
Check if you have enabled intrnet permision.
Go to
android/app/src/main/AndroidManifest.xml
and check if you have this line of code:
Happy Codding 🙂
you can use like this code to handle the images