gpt4 book ai didi

Flutter 展开 Container 填充 Row 的剩余空间

转载 作者:IT王子 更新时间:2023-10-29 06:53:47 29 4
gpt4 key购买 nike

我在一行中有一个图像,该图像旁边有一个文本。我希望行完全扩展并且图像作为其大小,然后保持完整区域应由容器占用。

这是我的代码片段:

Row(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(10, 50, 10, 8),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color.fromARGB(100, 0, 0, 0),
blurRadius: 5,
),
],
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Column(children: <Widget>[
Image.asset(
'assets/card.png',
height: 62,
width: 62,
fit: BoxFit.cover,
)
]),
Container(
child: Text("Hello world"),
)
],
),
),
],
),

我想要这样: Flutter UI

最佳答案

我建议您只使用 RowColumn 开始构建布局,以免混淆。我经常按如下方式构建布局。

  1. 仅具有RowColumn 的布局对象(例如文本、图像)。并在 RowColumn 中设置 mainAxisAlignmentcrossAxisAlignment 属性。
  2. 使用PaddingAlignExpanded等设置样式,也可以使用Container
  3. 另外装饰。

引用:

基本布局:

https://flutter.dev/docs/development/ui/layout

构建布局时的提示:

https://medium.com/@liewjuntung/tips-on-using-android-studio-to-develop-flutter-apps-9e42c047b7f4

希望对你有所帮助。

示例代码:


Widget buildCard() {
return Container(
margin: EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Color.fromARGB(100, 0, 0, 0),
blurRadius: 5,
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Image.asset(
'assets/card.png',
height: 62,
width: 62,
fit: BoxFit.cover,
),
Padding(
padding: const EdgeInsets.only(top: 12.0, left: 12.0),
child: Text(
"Hello world",
style: TextStyle(
fontWeight: FontWeight.w500,
letterSpacing: 0.8,
),
),
)
],
),
);
}

关于Flutter 展开 Container 填充 Row 的剩余空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54839870/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com