Flutter Network Image does not fit in Circular Avatar

后端 未结 23 1006
走了就别回头了
走了就别回头了 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:39
     CircleAvatar(
            radius: 26,
            backgroundColor: Colors.white,
            child: ClipOval(
              child: _bytesImage == null
                  ? new Text('No image value.')
                  : Image.memory(
                      _bytesImage,
                      width: 60,
                      height: 60,
                      fit: BoxFit.cover,
                    ),
            ),
          ),
    
    0 讨论(0)
  • 2020-12-29 02:46

    I had the same problem. Using clipoval in circle avatar will make it elliptical. But this fixed this issue.

    CircleAvatar(
    
                 radius:25.0,
    
                 backgroundImage: NetworkImage(
                            '${image_url}',
    
    
                            ),
                            backgroundColor: Colors.blue,
                                ),   
    
    
    0 讨论(0)
  • 2020-12-29 02:46

    Wrap your CircleAvatar widget under Stack widget.

     return Stack(
          children: [
            CircleAvatar(
              radius: 50.0,
              backgroundImage: NetworkImage(
                  'https://i.pinimg.com/474x/0c/eb/c3/0cebc3e2a01fe5abcff9f68e9d2a06e4.jpg'),
            ),
          ],
        );
    
    0 讨论(0)
  • 2020-12-29 02:47

    Here is a round picture with a shadow:

    child: AspectRatio(
        aspectRatio: 1/1,
        child: Container(
            margin: EdgeInsets.all(
                10.0
            ),
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(100.0),
                boxShadow:[
                  BoxShadow(
                      color: Color.fromARGB(60, 0, 0, 0),
                      blurRadius: 5.0,
                      offset: Offset(5.0, 5.0)
                  )
                ],
                image: DecorationImage(
                    fit: BoxFit.cover,
                    image: NetworkImage(user.image)
                )
            )
        )
    )
    
    0 讨论(0)
  • 2020-12-29 02:47

    If anyone is trying to fit a circular image in app bar actions. Try below solution it should work.

             Padding(
                padding: const EdgeInsets.all(8.0),
                child: AspectRatio(
                  aspectRatio: 1,
                  child: CircleAvatar(
                    backgroundImage: NetworkImage('https://picsum.photos/seed/picsum/200/500'),
    
                  ),
                ),
              )
    

    AspectRatio first tries the largest width permitted by the layout constraints(here the appbar). If I remove the padding image radius will be of appbar size. So add padding to control the size of circular image.

    0 讨论(0)
提交回复
热议问题