Rounded Corners Image in Flutter

后端 未结 15 1966
难免孤独
难免孤独 2020-12-22 18:34

I am using Flutter to make a list of information about movies. Now I want the cover image on the left to be a rounded corners picture. I did the following, but it didn’t wor

相关标签:
15条回答
  • 2020-12-22 19:09

    You can also use CircleAvatar, which comes with flutter

    CircleAvatar(
      radius: 20,
      backgroundImage: NetworkImage('https://via.placeholder.com/140x100')
    )
    
    0 讨论(0)
  • 2020-12-22 19:12

    Use ClipRRect it will work perfectly

    ClipRRect(
        borderRadius: BorderRadius.circular(8.0),
        child: Image.network(
            subject['images']['large'],
            height: 150.0,
            width: 100.0,
        ),
    )
    
    0 讨论(0)
  • 2020-12-22 19:12

    With new version of flutter and material theme u need to use the "Padding" widgett too in order to have an image that doesn't fill its container.

    For example if you want to insert a rounded image in the AppBar u must use padding or your image will always be as high as the AppBar.

    Hope this will help someone

    InkWell(
            onTap: () {
                print ('Click Profile Pic');
            },
            child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: ClipOval(
                    child: Image.asset(
                        'assets/images/profile1.jpg',
                    ),
                ),
            ),
        ),
    
    0 讨论(0)
  • 2020-12-22 19:14

    user decoration Image for a container.

      @override
      Widget build(BuildContext context) {
        final alucard = Container(
            decoration: new BoxDecoration(
            borderRadius: BorderRadius.circular(10),
              image: new DecorationImage(
                  image: new AssetImage("images/logo.png"),
                  fit: BoxFit.fill,
              )
            )
        );
    
    0 讨论(0)
  • 2020-12-22 19:16

    Try This it works well.

    Container(
      height: 220.0,
      width: double.infinity,
      decoration: BoxDecoration(
        borderRadius: new BorderRadius.only(
          topLeft: Radius.circular(10),
           topRight: Radius.circular(10),
        ),
        image: DecorationImage(
          fit: BoxFit.fill,
          image: NetworkImage(
            photoUrl,
          ),
         ),
       ),
    );
    
    0 讨论(0)
  • 2020-12-22 19:19

    Using ClipRRect you need to hardcode BorderRadius, so if you need complete circular stuff, use ClipOval instead.

    ClipOval(
      child: Image.network(
        "image_url",
        height: 100,
        width: 100,
        fit: BoxFit.cover,
      ),
    ),
    
    0 讨论(0)
提交回复
热议问题