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;

  Widget build(BuildContext context) {
    return SizedBox(
      height: 115,
      width: 115,
      child: Stack(
        fit: StackFit.expand,
        clipBehavior: Clip.none,
        children: [
            backgroundImage: NetworkImage(user?.photoURL ?? '') // I tried this but it return me nothing,
            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 :

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.

Leave a Reply