Flutter Network Image does not fit in Circular Avatar

后端 未结 23 1003
走了就别回头了
走了就别回头了 2020-12-29 02:06

I am trying to retrieve bunch of images from an api. I want the images to be displayed in Circular form so I am using CircleAvatar Widget, but I keep getting im

相关标签:
23条回答
  • 2020-12-29 02:21

    Had a similar problem in the AppBar actions widget list.

    This worked for me:

    CircleAvatar(
        radius: 18,
        child: ClipOval(
            child: Image.network(
              'image-url',
            ),
        ),
    ),
    
    0 讨论(0)
  • 2020-12-29 02:22

    I had the same problem

    CircleAvatar(
                 radius: 30.0,
                 backgroundImage: NetworkImage(imageURL),
                 backgroundColor: Colors.transparent,
                 ));
    

    fixed my issue.

    0 讨论(0)
  • 2020-12-29 02:27

    It took a few tries to figure this one out.. All these answers did not help me. In the end picture that I inserted into the circle avatar was stretched out to the boundaries of the container that was 2 instances above it. Maybe there are are people who, after going through the answers here, still have the problem that I had. I solved the constraint issue with a FittedBox

                 GestureDetector(
                        onTap: () => getImage(),
                        child: Container(
                          width: MediaQuery.of(context).size.width,
                          decoration: BoxDecoration(
                            color: Colors.orange,
                          ),
                          //padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
                          child: Container(
                              width: 140,
                              height: 160,
                              child: FittedBox(
                                child: picture(),
                              )),
                        ),
                      ),
    

    This is the code for the picture() that I use. I think that the container inside the picture() is not necessary anymore, try it yourself :)

    Widget picture() {
    if (_image == null) {
      return CircleAvatar(
          radius: 70,
          child: Icon(
            Icons.person,
            size: 150,
            color: Colors.grey[900],
          ));
    } else {
      return Container(
        width: 140,
        height: 140,
        child: CircleAvatar(
          radius: 70,
          backgroundImage: FileImage(_image),
        ),
      );
    }
    
    0 讨论(0)
  • 2020-12-29 02:28
    Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.spaceAround,
                    children: [
                      GestureDetector(
                        onTap: () {
                          Navigator.push(
                            context,
                            MaterialPageRoute(builder: (context) => MyApp7()),
                          );
                        },
                        child: CircleAvatar(
                          radius: 50,
                          // backgroundColor: Colors.amber,
                          child: CircleAvatar(
                              backgroundColor: Colors.grey[50],
                              radius: 50,
                              // child: Image.asset("assets/images/nophotoMale.png")
                              backgroundImage:
                                  AssetImage("assets/images/nophotoMale.png")),
                        ),
                      ),
                    ],
                  ),
    
    0 讨论(0)
  • 2020-12-29 02:28

    if someone intends to create bordered circular image try this.

    Using ClipOval widget is not perfect solution because if images are not square result will be elliptic.

    CircleAvatar(radius: (52),
                backgroundColor: Colors.white,
                child: ClipRRect(
                  borderRadius:BorderRadius.circular(50),
                  child: Image.asset("assets/pictures/profile.png"),
                )
            )
    

    ClipRRect widget prevents image to overflow CircleAvatar widget.

    0 讨论(0)
  • 2020-12-29 02:29
      ClipOval(
         child: Image.asset(
          'assets/dummy.jpg',
           fit: BoxFit.contain,
           matchTextDirection: true,
           height: 50,
       ))
    
    0 讨论(0)
提交回复
热议问题