-2

「RenderFlex が下部で 23 ピクセルオーバーフローしました」という例外を解決するにはどうすればよいですか。私のアプリでは、Gridview を作成しました。コードを実行するたびにRenderFlexを取得します。Gridview を expnded add でラップします

  1. scrollDirection: Axis.vertical,
  2. シュリンクラップ: 真、

しかし、この例外を取得しても効果はありません。誰でも私を修正できますか; 私のコードで何が間違っていますか?そして、私は何をしなければなりませんか。

エラーが発生しているコードは次のとおりです。

Widget build(BuildContext context) {
    return Scaffold(
       body:Container(
            height: 150,
            width: MediaQuery.of(context).size.width,
            color: Colors.grey[100],
            child: Column(children: [
              Expanded(
                child: Padding(
                  padding: EdgeInsets.fromLTRB(10, 40, 0, 0),
                  child: Container(
                    child: Column(
                      children: [
                        Align(
                        alignment: Alignment.centerLeft,
                          child: Container(
                            child: Text('Oliver Queen'),
                          ),
                        ),
                        SizedBox(height:5),
                        Align(
                          alignment: Alignment.centerLeft,
                          child: Container(
                            child: Text('olieequeen77@gmail'),
                          ),
                        ),
                        SizedBox(height:5),
                        Align(
                          alignment: Alignment.centerLeft,
                          child: Container(
                            child: Text('9874561239'),
                          ),
                        ),
                      ],
                    ),
                  ),
                ), 
              ),

             Expanded(
               child: GridView(
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
                  scrollDirection: Axis.vertical,
                  shrinkWrap: true,
                  children: <Widget>[
                    Container(
                      color: Colors.grey[100],
                      height: 90.0,
                      width: 110.0,
                       child: TextButton(onPressed: (){

                       },
                        child: Column(children: [
                        Icon(Icons.home,size: 45,
                         color: Colors.purple,),
                         Text("My Settings",
                         style: TextStyle(fontSize: 12,color: Colors.black)),
                       ],),
                       ),    
                     ),
                      Container(
                      color: Colors.grey[100],
                      height: 90.0,
                       width: 110.0,
                       child: TextButton(onPressed: (){

                       },
                        child: Column(children: [
                        Icon(Icons.home,size: 45,
                         color: Colors.purple,),
                         Text("My Settings",
                         style: TextStyle(fontSize: 12,color: Colors.black)),
                       ],),
                       ),
                     ),
                      Container(
                      color: Colors.grey[100],
                      height: 90.0,
                       width: 110.0,
                       child: TextButton(onPressed: (){

                       },
                        child: Column(children: [
                        Icon(Icons.home,size: 45,
                         color: Colors.purple,),
                         Text("My Settings",
                         style: TextStyle(fontSize: 12,color: Colors.black)),
                       ],),
                       ),
                     ),
                      Container(
                      color: Colors.grey[100],
                      height: 90.0,
                       width: 110.0,
                       child: TextButton(onPressed: (){

                       },
                        child: Column(children: [
                        Icon(Icons.home,size: 45,
                         color: Colors.purple,),
                         Text("My Settings",
                         style: TextStyle(fontSize: 12,color: Colors.black)),
                       ],),
                       ),
                     ),
                      Container(
                      color: Colors.grey[100],
                      height: 90.0,
                       width: 110.0,
                       child: TextButton(onPressed: (){

                       },
                        child: Column(children: [
                        Icon(Icons.home,size: 45,
                         color: Colors.purple,),
                         Text("My Settings",
                         style: TextStyle(fontSize: 12,color: Colors.black)),
                       ],),
                       ),
                     ),
                  ],
               ),
             )
            ],
          ),
        ), 
      );
     }
  }

見た目はこんな感じ

4

1 に答える 1

1

Container高さを変更してみてください200

return Scaffold(
  body: Container(
    height: 200,
    width: MediaQuery.of(context).size.width,
    color: Colors.grey[100],
    child: Column(
      children: [
        Expanded(
          child: Padding(
            padding: EdgeInsets.fromLTRB(10, 40, 0, 0),
            child: Container(
              child: Column(
                children: [
                  Align(
                    alignment: Alignment.centerLeft,
                    child: Container(
                      child: Text('Oliver Queen'),
                    ),
                  ),
                  SizedBox(height: 5),
                  Align(
                    alignment: Alignment.centerLeft,
                    child: Container(
                      child: Text('olieequeen77@gmail'),
                    ),
                  ),
                  SizedBox(height: 5),
                  Align(
                    alignment: Alignment.centerLeft,
                    child: Container(
                      child: Text('9874561239'),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
        Expanded(
          child: GridView(
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2),
            scrollDirection: Axis.vertical,
            shrinkWrap: true,
            children: <Widget>[
              Container(
                color: Colors.grey[100],
                height: 90.0,
                width: 110.0,
                child: TextButton(
                  onPressed: () {},
                  child: Column(
                    children: [
                      Icon(
                        Icons.home,
                        size: 45,
                        color: Colors.purple,
                      ),
                      Text("My Settings",
                          style:
                              TextStyle(fontSize: 12, color: Colors.black)),
                    ],
                  ),
                ),
              ),
              Container(
                color: Colors.grey[100],
                height: 90.0,
                width: 110.0,
                child: TextButton(
                  onPressed: () {},
                  child: Column(
                    children: [
                      Icon(
                        Icons.home,
                        size: 45,
                        color: Colors.purple,
                      ),
                      Text("My Settings",
                          style:
                              TextStyle(fontSize: 12, color: Colors.black)),
                    ],
                  ),
                ),
              ),
              Container(
                color: Colors.grey[100],
                height: 90.0,
                width: 110.0,
                child: TextButton(
                  onPressed: () {},
                  child: Column(
                    children: [
                      Icon(
                        Icons.home,
                        size: 45,
                        color: Colors.purple,
                      ),
                      Text("My Settings",
                          style:
                              TextStyle(fontSize: 12, color: Colors.black)),
                    ],
                  ),
                ),
              ),
              Container(
                color: Colors.grey[100],
                height: 90.0,
                width: 110.0,
                child: TextButton(
                  onPressed: () {},
                  child: Column(
                    children: [
                      Icon(
                        Icons.home,
                        size: 45,
                        color: Colors.purple,
                      ),
                      Text("My Settings",
                          style:
                              TextStyle(fontSize: 12, color: Colors.black)),
                    ],
                  ),
                ),
              ),
              Container(
                color: Colors.grey[100],
                height: 90.0,
                width: 110.0,
                child: TextButton(
                  onPressed: () {},
                  child: Column(
                    children: [
                      Icon(
                        Icons.home,
                        size: 45,
                        color: Colors.purple,
                      ),
                      Text("My Settings",
                          style:
                              TextStyle(fontSize: 12, color: Colors.black)),
                    ],
                  ),
                ),
              ),
            ],
          ),
        )
      ],
    ),
  ),
);
}
于 2021-04-03T18:57:39.540 に答える