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

I'm trying to get the photoURL of the user signed in by google accounts

I tried using (user!.photoURL) but it was an error The argument type 'String?' can't be assigned to the parameter type 'String'. At first it was okay but suddenly after rebooting it throws me error. I use (user!.photoURL!), I thought it was okay because in my editor there’s no error, but when I run it , the error shows me null error. And finally using (user?.photoURL ?? ''), it returns me "", Invalid argument(s): No host specified in URI file:/// .The photoURL is from the google sign in.

  User? user = FirebaseAuth.instance.currentUser;

  @override
  Widget build(BuildContext context) {
    
    return SizedBox(
      height: 115,
      width: 115,
      child: Stack(
        fit: StackFit.expand,
        clipBehavior: Clip.none,
        children: [
          CircleAvatar(
            backgroundImage: NetworkImage(user?.photoURL ?? '') // I tried this but it return me nothing,
          ),
          Positioned(
            right: -16,
            bottom: 0,
            child: SizedBox(
              height: 46,
              width: 46,
              child: TextButton(
                style: TextButton.styleFrom(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(50),
                    side: const BorderSide(color: Colors.white),
                  ),
                  primary: Colors.white,
                  backgroundColor: const Color(0xFFF5F6F9),
                ),
                onPressed: () {},
                child: SvgPicture.asset("assets/icons/Camera Icon.svg"),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

>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 NetworkImage('${user!.photoURL}'). A network image will need a string value. Your code was trying to assign a value that can be null also. Now if you add it inside a string if user is null you still have an empty string.

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