Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Gridview in Column. What's solution..?

Tags:

flutter

I have a problem with gridview and column. In this case, i want put an image in upper of gridview. Please give me a solution..

return new Container(   child: new Column(     children: <Widget>[       new Container(         child: new Image.asset(           "assets/promo.png",           fit: BoxFit.cover,         ),       ),       new Container(         child: new GridView.count(           crossAxisCount: 2,           childAspectRatio: (itemWidth / itemHeight),           controller: new ScrollController(keepScrollOffset: false),           shrinkWrap: true,           scrollDirection: Axis.vertical,           children: new List<Widget>.generate(16, (index) {             return new GridTile(                 header: new Container(                   padding: const EdgeInsets.all(10.0),                   alignment: Alignment.centerRight,                   child: new Icon(                     Icons.shopping_cart,                     size: 20.0,                     color: Colors.red,                   ),                 ),                 child: new MyList(                   nomor: '$index',                 ));           }),         ),       ),     ],   ), ); 

and this is the result: Flutter Gridview in Column

like image 565
Anam Khoirul Avatar asked Apr 20 '18 13:04

Anam Khoirul


People also ask

How do you put GridView in column Flutter?

You just need to put your GridView Widget into the Expanded Widget, for example: body: new Column( children: <Widget>[ new Expanded( child: GridView. count( // Create a grid with 2 columns. If you change the scrollDirection to // horizontal, this would produce 2 rows.

What is gridDelegate Flutter?

gridDelegate property Null safetyA delegate that controls the layout of the children within the GridView. The GridView, GridView. builder, and GridView. custom constructors let you specify this delegate explicitly. The other constructors create a gridDelegate implicitly.


1 Answers

You just need to put your grid view into Expanded widget, for example:

body: new Column(   children: <Widget>[     new Expanded(       child: GridView.count(         // Create a grid with 2 columns. If you change the scrollDirection to         // horizontal, this would produce 2 rows.         crossAxisCount: 2,         // Generate 100 Widgets that display their index in the List         children: List.generate(10, (index) {           return _buildCard(index);         }),       ),     ),     new Text("text")   ], ), 
like image 71
Ruslan Leshchenko Avatar answered Oct 01 '22 03:10

Ruslan Leshchenko