Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

networkImage error handling/placeholder not working

How can i add a network handling/placeholder in networkimage when the url return null?

  body: Center(
        child: ListView.builder(
            itemCount: users.length,
            itemBuilder: (BuildContext context, int index) {
              User user = users[index];
              return ListTile(
                  title: Text(user.firstName),
                
                  subtitle: Text(user.role),
                  leading: CircleAvatar(
                    backgroundImage: NetworkImage(user.avatar.toString()),
                     errorWidget: (context, url, error) =>  //this part not working
                     Icon(Icons.error),
                  ),
                  onTap: () {});
            })));

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use following code.

body: Center(
        child: ListView.builder(
            itemCount: users.length,
            itemBuilder: (BuildContext context, int index) {
              User user = users[index];
              return ListTile(
                  title: Text(user.firstName),
                
                  subtitle: Text(user.role),
                  leading: CircleAvatar(
                    backgroundImage: Image.network('ImageURL....',
                            errorBuilder: (context, exception, stackTrace) {
                              return const Icon(Icons.error);
                            },
                          ), 
                  onTap: () {});
            })));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading