flutter - SizedBox 在 listview-Flutter 中不起作用
问题描述
Scaffold(
appBar: AppBar(
leading: Icon(Icons.arrow_back),
centerTitle: true,
title: Text("Select Time Slot"),
),
body: ListView(
children: <Widget>[
SizedBox(
width: 150,
child: Card(
child: Text(
"11 AM - 1 PM",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
),
)
],
),
);
我希望该卡占用 150 宽,但它占用了完整的可用宽度。
我应该怎么做才能得到预期的结果?
解决方案
如果您想以 150 宽度居中卡片,请使用中心小部件将其包裹起来。center 小部件会将卡片宽度设置为 150,并将通过将卡片居中到中间来填充剩余宽度。
Center(child:
SizedBox(
width: 150,
child: Card(
child: Text(
"11 AM - 1 PM",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
),
))
],
否则,您可以使用对齐小部件根据您的喜好对齐卡片。
推荐阅读
- java - 引起:java.lang.ClassNotFoundException:org.eclipse.core.runtime.Plugin
- excel - VBA Application.Ontime 错误 438。对象不支持此属性或方法
- c# - MVC5 Portable Area,如何使用消息总线?
- java - Swing 中的每个点颜色
- unity3d - Unity 奇怪的错误 [9:14:44] 关于它可能是什么的任何想法?
- python - 使用 simpy.optimize.bisect 查找函数的零点,具有复杂函数
- powershell - powershell中的Serial Comm需要处理数据输入
- javascript - JavaScript 添加到 requestAnimationFrame 函数
- android - 如何在 Android API 29 中获取缩略图
- flutter - Flutter ListView中如何传递参数