0

i want to fetch the image of my products in my flutter app ...

but i cant it show me this weird error and i don't know what is it for?

enter image description here

and this is my code ( exactly based on a tutorial that worked for the teacher) :

class _MyPageState extends State<MyPage> {
  late List<Product>? listproduct;

  @override
  void initState() {
    fetchAllProducts().then((value) => listproduct = value);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FutureBuilder(
        future: fetchAllProducts(),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return ListView.builder(
              itemCount: listproduct!.length,
              itemBuilder: (context, index) {
                return Card(
                  child: ListTile(
                    title: Text(listproduct![index].name.toString()),
                    subtitle: Text('${listproduct![index].price} تومان'),
                    leading:
                        Image.network(listproduct![index].images!.join(', ')),
                  ),
                );
              },
            );
          } else if (snapshot.hasError) {
            return Text('${snapshot.error}');
          } else {
            return const Center(child: CircularProgressIndicator());
          }
        },
      ),
    );
  }
}
5
  • what teh response from api ? Commented Jul 3, 2024 at 13:09
  • ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ The following ImageCodecException was thrown resolving an image codec: Failed to detect image file format using the file header. File header was [0x3c 0x21 0x44 0x4f 0x43 0x54 0x59 0x50 0x45 0x20]. Image source: encoded image bytes Commented Jul 3, 2024 at 14:18
  • Image provider: NetworkImage("Instance of 'Images'", scale: 1) Image key: NetworkImage("Instance of 'Images'", scale: 1) Commented Jul 3, 2024 at 14:18
  • Why you using join(', ') ? Also Make sure, Image url is getting on response? Commented Jul 3, 2024 at 14:45
  • 3c 21 44 4f => "<!DOCTYPE" so the server is responding with HTML (?) rather than an image. Try accessing the link directly and see if get a human readable error message that can point you in the right direction. Commented Jul 3, 2024 at 16:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.