简体   繁体   English

底部溢出 21 个像素的 RenderFlex

[英]A RenderFlex overflowed by 21 pixels on the bottom

I'm newbie in the flutter and I try use Grid View but it shows a render flex overflowed by 21 pixels on the bottom.我是 flutter 的新手,我尝试使用网格视图,但它显示了一个渲染弯曲,底部溢出了 21 个像素。 In the GridView I'm using picture, but it shows error.在 GridView 我使用图片,但它显示错误。 Anyone know how to fix it?谁知道怎么修它? Thank you谢谢

I search on the internet, it use SingleChildScrollView, but I don't want to use it because it looks weird for the Grid view我在互联网上搜索,它使用 SingleChildScrollView,但我不想使用它,因为网格视图看起来很奇怪

Here my code这是我的代码

import 'package:flutter/material.dart';
import 'package:monger_app/page/detail.dart';

class BudgetSettings extends StatefulWidget {
  @override
  _BudgetSettingsState createState() => _BudgetSettingsState();
}

class _BudgetSettingsState extends State<BudgetSettings> {
  List<Container> categorylist = new List();

  var character=[
    {"name":"Food", "image":"food.png"},
    {"name":"Social-Life", "image":"travel.png"},
    {"name":"Transportation", "image":"transportation.png"},
    {"name":"Beauty", "image":"makeup.png"},
    {"name":"Household", "image":"household.png"},
    {"name":"Education", "image":"education.png"},
    {"name":"Health", "image":"health.png"},
    {"name":"Gift", "image":"gift.png"},
    {"name":"Other", "image":"other.png"},
  ];
  _makelist() async {
    for (var i = 0; i < character.length; i++) {
      final newcharacter = character[i];
      final String image = newcharacter["image"];
      categorylist.add(
        new Container(
          padding: new EdgeInsets.all(20.0),
          child: new Card( child:
            new Column(
                  children: <Widget>[
                    new Image.asset('assets/$image', fit: BoxFit.cover,),
                    new Padding(padding: new EdgeInsets.all(5.0),),
                    new Text(newcharacter['name'], style: new TextStyle(fontSize: 18.0),),
                  ],
                ),
            ),
            )
        );
    }
  }

  @override
  void initState() {
    _makelist();
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Budget Setting'),
      ),

      body: new GridView.count(
          crossAxisCount: 2,
          children: categorylist,
      ),
    );
  }
}

And here my output这里是我的 output 在此处输入图像描述

A simple solution for your problem is wrapping your image widget inside a Flexible widget, just like this:您的问题的一个简单解决方案是将您的图像小部件包装在一个灵活的小部件中,就像这样:

Flexible(
  child: Image.asset('assets/$image', fit: BoxFit.cover,),
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM