I was trying to use a string inside the Network Image, even though the String has value it does shows me error

class HomePage extends StatelessWidget {
  HomePage(
      {super.key, required this.mailId, required this.name, required this.pic});

  String mailId;
  String name;
  String pic = "data:image/webp;base64,UklGOOOyAR0vA6w6+gjEQiUr+bqpnJ/uGmjaRdZFh40GKjdvH1pau8C0saW81R0lAty9idmf0CrPXpzp6gr11ZILJOuAAAAAAAAAAAAAA==";

  @override
  Widget build(context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Home page"),
        backgroundColor: Colors.amber,
        actions: [
          GestureDetector(
            onTap: () {
              Navigator.of(context).pop(
                MaterialPageRoute(
                    builder: (context) =>
                        ProfilePage(pic,mailID: mailId, name: name, img: pic)),
                        

              );

              //ProfilePage(mailID: mailId, name: name, img: pic);
            }, 
            child:  const CircleAvatar(
              radius: 30,
              backgroundImage: NetworkImage(pic),
            ),
          )
        ],
      ),

I tried to assign the string as const but it’s not allowing it, as you can see I assigned the image url to the String & tried to use it inside the network image, but returning an error. I tried even null check pointer still it showing me errors.NOTE: not an valid url in the snippet.

  • have you check with another URL.? and what the error says ?

    – 

Your image URL is not in the correct format, use something like this for network image

String pic =  "https://images.pexels.com/photos/18184356/pexels-photo-18184356/free-photo-of-south-american-coati-in-nature.jpeg";

Leave a Comment