Home > Software design >  In Flutter, I can't center cards in containers
In Flutter, I can't center cards in containers

Time:11-10

  return Scaffold(
    body: Center(
  child: Row(
    crossAxisAlignment: CrossAxisAlignment.center,
    children: [
      Container(
        color: Colors.red,
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        child: Center(
          child: SelectGroupCard(context, titles: titles, ids: ids,
              onTap: (title, id) {
            setState(() {
              cardGroupResult = title   " "   id;
            });
          }),
        ),
      ),
    ],
  ),

enter image description here

There are several cards as seen in the picture. I want to get these right out. I even want to be able to show these cards in the middle of the page, in 3 columns, 4 rows.

CodePudding user response:

Use widget GridView, it allows you to select the desired number of columns and rows. Also, it is possible to install paddings.

CodePudding user response:

you can use GridView

GridView(
   gridDelegate:const SliverGridDelegateWithFixedCrossAxisCount(
       crossAxisCount:  2, // you can change this
   ),      
   children :[...] // put your cards here !
)
  • Related