如何设置网格视图列高?

Mid*_*laj 11 flutter flutter-layout

我是新手,没有太多经验。
我正在尝试使用 flutter 开发一个 android 应用程序,这是我以前的应用程序设计。

在此处输入图片说明

而且我也能够在颤动中成功制作网格视图,但列高是问题所在。他们的任何人都可以帮助我处理我的颤振代码。

 class MyHomePage extends StatelessWidget {

  @override
   Widget build(BuildContext context) {
     hi(){

    }
     return new Scaffold(

         appBar: new AppBar(
           actions: <Widget>[],
                title: new Text("milla"),
              ),
       body: new Container(


         child: new Center(

            child: new GridView.count(
              shrinkWrap: true,
              scrollDirection: Axis.vertical,
              childAspectRatio:1.0,
              crossAxisCount: MediaQuery.of(context).size.width <= 400.0 ? 3 : MediaQuery.of(context).size.width >= 1000.0 ? 5 : 4,

           // Create a grid with 2 columns. If you change the scrollDirection to
           // horizontal, this would produce 2 rows.

           crossAxisSpacing: 2.0,
           // Generate 100 Widgets that display their index in the List
           children: new List.generate(100, (index) {

             return  new Column(
                 crossAxisAlignment: CrossAxisAlignment.stretch,
                 mainAxisSize: MainAxisSize.min,

                 verticalDirection: VerticalDirection.down,
                 children: <Widget>[


                   new Center(

                     child:  new Image(


                         image: new NetworkImage('https://github.com/flutter/website/blob/master/_includes/code/layout/lakes/images/lake.jpg?raw=true')
                     )
                   ),
                   new Expanded(child: new Text("apple2")), new Expanded(child: new Text(
                   'Item $index',
                   style: Theme.of(context).textTheme.headline,
                 )),new Expanded(child: new Center(child: new Row(
                     crossAxisAlignment: CrossAxisAlignment.center,

                     children: <Widget>[new Text("+",style: new TextStyle(fontSize: 24.0),),new Text("1"),new Text("-")])))]
             );
           }),
         ),
        ),
      )
     );
   }
 }
Run Code Online (Sandbox Code Playgroud)

这是我的输出。在此处输入图片说明

如何设置列高?
当我尝试添加新视图时,它显示此错误
“抛出了另一个异常:RenderFlex 在底部溢出了 21 个像素。”

Goo*_*gle 14

把这个而不是

childAspectRatio:1.0 to  childAspectRatio: (itemWidth / itemHeight)

var size = MediaQuery.of(context).size;
 final double itemHeight = (size.height) / 2;
 final double itemWidth = size.width / 2;
Run Code Online (Sandbox Code Playgroud)

在我的代码中可以很好地设置 Gridview 的高度和宽度

  • 如果 itemHeight 是动态的,我们如何知道它 (4认同)

Abd*_*pal 8

你可以试试这个:

GridView.count(
   crossAxisCount: 2,
   childAspectRatio: MediaQuery.of(context).size.height / 400,
   children: <Widget>[...]
);
Run Code Online (Sandbox Code Playgroud)


stu*_*low 2

尝试这个

childAspectRatio: mediaQueryData.size.height / 1000,
Run Code Online (Sandbox Code Playgroud)

在哪里

MediaQueryData mediaQueryData = MediaQuery.of(context);
Run Code Online (Sandbox Code Playgroud)

我在某处看到了这段代码,对我来说看起来不错。