Reputation: 1
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?
Upvotes: 0
Views: 83
Reputation: 11
you can use like this code to handle the images
class app {
static String icon = "assets/icon.jpg";
}
Container(
width: 100.0,
height: 100.0,
decoration: BoxDecoration(
image: DecorationImage(
image: app.icon.startsWith('http')
? NetworkImage(app.icon) as ImageProvider
: AssetImage(app.icon) as ImageProvider,
fit: BoxFit.cover,
),
shape: BoxShape.circle,
),
),
Upvotes: 0
Reputation: 733
Check if you have enabled intrnet permision.
Go to android/app/src/main/AndroidManifest.xml
and check if you have this line of code:
<uses-permission android:name="android.permission.INTERNET" />
Happy Codding :)
Upvotes: 0