1

I have been reading some answers to this question at stackoverflow but no one has worked for me. For example this one: Flutter how to handle Image.network error (like 404 or wrong url)

Here the code:

ListView.builder(
              itemCount: steamUsers.length,
              itemBuilder: (context, index) => ListTile(
                    leading: CircleAvatar(
                      child: steamUsers[index].avatarUrl != null
                          ? Image.network(
                              steamUsers[index].avatarUrl!,
                              errorBuilder: (context, error, stackTrace) {
                                return
                                  const Icon(Icons.person);
                              },
                            )
                          : const Icon(Icons.person),
                    ),
                    title: Text(steamUsers[index].accountName),
                    subtitle: Text(steamUsers[index].personName),
                  )),

How can I avoid flutter throwing an exception when picture is not found (404)? Notice I'm already using the errorBuilder property.

The exception dump is:

HTTP request failed, statusCode: 404, https://avatars.akamai.steamstatic.com/5e3a3f851ea968aa4a35fa454ddfe5acafe2ec3.jg

Notbad
  • 5,936
  • 12
  • 54
  • 100

0 Answers0