Ad

How To Implement GridView In Column In Flutter?

- 1 answer

i have a SingleChildScrollView that contains a form and Form cotains a Column. now i want to use GridView like this:

return SingleChildScrollView(
    child: Container(
  width: MediaQuery.of(context).size.width,
  alignment: Alignment.center,
  decoration: BoxDecoration(
      color: Color(0xffffffff),
      borderRadius: BorderRadius.all(Radius.circular(20))),
  margin: EdgeInsets.only(
      right: 25, left: 25, top: MediaQuery.of(context).size.height * .12),
  child: Form(
    key: _formKey,
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        new InputFieldArea(
          icon: Icons.person,
          controller: _payValController,
          lable: 'مبلغ',
          maxLength: 9,
          validator: (value) {
            if (value.isEmpty) {
              return 'لطفا این فرم را پر کنید';
            }
            return null;
          },
          textInputType: TextInputType.number,
        ),
       
        
        _imagesAssets.length > 0
            ? new SizedBox(
                child: _buildGridView(),
              )
            : Container(),
        
            
        _submit(context),
      ],
    ),
  ),
));

this is my gridView:

Widget _buildGridView() {
return GridView.count(
  crossAxisCount: 2,
  padding: EdgeInsets.all(10),
  children: List.generate(_imagesAssets.length, (index) {
    Asset asset = _imagesAssets[index];
    return AssetThumb(
      asset: asset,
      width: 100,
      height: 100,
    );
  }),
);

}

but i got this render error: RenderBox was not laid out: RenderRepaintBoundary#3ec8a relayoutBoundary=up18 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': Failed assertion: line 1930 pos 12: 'hasSize' any idea will be greate

Ad

Answer

In GridView use these below parameters

shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),

or you can give fix height to your grid view widget.

Ad
source: stackoverflow.com
Ad