Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Scale type center crop on flutter?

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 centerCrop works on android.

 Widget bindItem(BuildContext context, int index) { return new Card(     child: new Column(         children: <Widget>[           new Image.network(             _parties[index]["cover"], fit: BoxFit.fitWidth,             height: 120.0,           ),           new Text(_parties[index]['name'])         ]     ) ); 

}

@override       Widget build(BuildContext context) {         return new Scaffold(             appBar: new AppBar(               title: new Text("Parties"),             ),             body: new ListView.builder(               itemCount: _parties == null ? 0 : _parties.length,               itemBuilder: bindItem,             )         );       } 

Result: enter image description here

like image 674
Boldijar Paul Avatar asked Mar 05 '18 21:03

Boldijar Paul


1 Answers

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.

like image 105
Antonino Avatar answered Sep 21 '22 21:09

Antonino