1

I've noticed that GridView makes each child a square.. Is there any way to adjust height of each child which means entire row of GridView row in GridView.builder?

In this example I want to have each input next to each other.

List<Map<String, dynamic>> list = [
  {'description': 'des1'},
  {'description': 'des2'},
  {'description': 'des3'},
  {'description': 'des4'},
  {'description': 'des5'},
  {'description': 'des6'}
];

class _MaterialScreenState extends State<MaterialScreen> {
  String text = '';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
      children: <Widget>[
        Text(text),
        GridView.builder(
            shrinkWrap: true,
            itemCount: list.length,
            gridDelegate:
                SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 5),
            itemBuilder: (BuildContext context, int index) {
              return TextFormField(
                textAlign: TextAlign.center,
                onTap: () => setState(() {
                  text = list[index]['description'];
                }),
                decoration: InputDecoration(border: OutlineInputBorder()),
              );
            }),
      ],
    ));

Problem:

enter image description here

Reason:

enter image description here

2 Answers 2

1

How about this?

gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
  maxCrossAxisExtent: 200,
  childAspectRatio: 3,
),

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

hmm... I guess that would work even when I wanted to have fixed number of items in one row this is so far the best workaround
0

Yoy can use "childAspectRatio".

gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  crossAxisCount: 5,
  childAspectRatio: 2,
),

sample

1 Comment

Yes.. but that doesn't make it fixed... does it? try to rotate the display

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.