Image Scale type center crop on flutter?

后端 未结 4 1016
南方客
南方客 2021-02-05 05:31

I\'m trying to do something similar to centerCrop property from android ImageView. Setting the height of the imageview, and making it crop and align to center, just as centerCro

相关标签:
4条回答
  • 2021-02-05 05:49

    Please add this following width and height to the image

    Note: We are zooming the image

    height: double.infinity, 
    width: double.infinity,`
    
    0 讨论(0)
  • 2021-02-05 05:53

    Android ScaleType and BoxFit should match like this:

    1. CENTER = none
    2. CENTER_CROP = Cover
    3. CENTER_INSIDE = scaleDown
    4. FIT_CENTER = contain (alignment.center)
    5. FIT_END = contain (alignment.bottomright)
    6. FIT_START = contain (alignment.topleft)
    7. FIT_XY = Fill

    So you should use Cover to achieve the CENTER_CROP result.

    EDIT:

    The problem should be crossAxisAlignment of the Column widget. Setting this property to crossAxisAlignment: CrossAxisAlignment.stretch should fix your issue.

    0 讨论(0)
  • 2021-02-05 05:57
    new Center(
                      child: Container(
                        child: new Stack(
                          children: <Widget>[
                            new Image.asset(
                              'assets/images/firebase1.png',
                              width: 100.0,
                              height: 100.0,
                            ),
                          ],
                        ),
                      ),
                    ),
    
    0 讨论(0)
  • 2021-02-05 05:58
    new Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
            new Expanded(child: new Image.network(
                cover.img,fit: BoxFit.fitWidth,
            ),
    
            ),
            Text(cover.name),
          ]
        )
    

    this works for me

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