ElevatedButton 在 Flutter Android 上不占用父级的高度

问题描述 投票:0回答:1

就像标题一样,您可以看到我的按钮没有占据行的整个高度。蓝色背景颜色是容器包裹我的按钮以可视化容器大小。您可以在下面看到没有背景颜色的图像。 我不知道是什么原因造成的,在互联网上找不到任何答案,所以我将其发布在这里。下面是我的代码和图像。谢谢您的帮助。

@override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Center(
            child: Container(
              padding: EdgeInsets.all(16),
              // color: Colors.redAccent,
              child: Container(
                // color: Colors.indigo,
                child: Column(
                  children: [
                    Row(
                      children: [
                        Expanded(
                          child: TextField(
                            decoration: InputDecoration(
                              contentPadding: EdgeInsets.symmetric(
                                  horizontal: 8, vertical: 0),
                              border: OutlineInputBorder(
                                borderRadius: BorderRadius.circular(10),
                              ),
                              hintText: 'Enter Match ID',
                            ),
                          ),
                        ),
                        Container(
                          // color: Colors.blue,
                          padding: EdgeInsets.all(0),
                          margin: EdgeInsets.all(0),
                          child: ElevatedButton(
                              style: ElevatedButton.styleFrom(
                                // backgroundColor: Colors.greenAccent,
                                shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(10)),
                              ),
                              onPressed: () => {},
                              child: Text("Scan Code")),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

我画背景是为了研究问题 原创

我尝试过 Expand、SizedBox、SizedBox.expand...但没有任何效果。我认为问题在于按钮本身,或者也许我还不理解按钮。

android flutter dart button layout
1个回答
0
投票

根本没那么高。默认情况下,行的子级不会拉伸整个高度。为此,您可以尝试给予

Row

crossAxisAlignment: CrossAxisAlignment.stretch,
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.