flutter - 将列的每个子项扩展到顶部和底部
问题描述
我试图从
至
但我不确定如何将列的顶部标题限制在其顶部,将副标题限制在其底部。我使用了具有适当弹性因子的 Expanded 以使每一列(左一列和右一列)适当地显示它们的数据并使用 mainAxis/crossAxis 值限制它们的位置。不过,我怎样才能对列的子项做同样的事情呢?
这是用于列表中每个项目的有状态小部件:
class PickUpGameItem extends StatefulWidget {
final String gameId;
final PickUpGameDetails details;
const PickUpGameItem(this.gameId, this.details, Key? key) : super(key: key);
@override
_PickUpGameItemState createState() => _PickUpGameItemState();
}
class _PickUpGameItemState extends State<PickUpGameItem> {
PickUpGameDetails? _gameDetails;
GameDetailsBloc? _detailsBloc;
@override
void initState() {
super.initState();
_detailsBloc = BlocProvider.of<GameDetailsBloc>(context);
_detailsBloc!.subscribeToGameDetailsUpdatesWithId(widget.gameId);
}
@override
Widget build(BuildContext context) {
return StreamBuilder<Tuple2<String, PickUpGameDetails>>(
stream: _detailsBloc!.detailsUpdatesStream,
builder: (context, snapshot) {
if (snapshot.hasError ||
snapshot.connectionState == ConnectionState.waiting) {
return const SizedBox();
} else {
if (snapshot.data!.item1 == widget.gameId) {
_gameDetails = snapshot.data!.item2;
} else {
_gameDetails = widget.details;
}
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
child: Row(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(10.0),
child: _gameDetails!.locationInfo == null
? const SizedBox()
: CachedNetworkImage(
imageUrl:
_gameDetails!.locationInfo!.pictures.elementAt(0),
width: 85,
height: 85,
fit: BoxFit.cover,
placeholder: (context, url) => const SizedBox(
child: Center(child: CircularProgressIndicator()),
width: 10,
height: 10),
),
),
const SizedBox(
width: 10,
),
Expanded(
flex: 7,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_gameDetails!.locationInfo == null
? 'Loading...'
: _gameDetails!.locationInfo!.nam,
style: const TextStyle(
fontFamily: 'PingFang',
fontWeight: FontWeight.w600,
fontSize: 15),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
_gameDetails!.gameData!.hostInfo == null
? Text(
_gameDetails!.gameData!.gameTypeMsg!,
style: const TextStyle(
color: Colors.black,
fontFamily: 'PingFang',
fontWeight: FontWeight.w200,
fontSize: 16),
maxLines: 2,
overflow: TextOverflow.ellipsis,
)
: Text(
'${_gameDetails!.gameData!.gameTypeMsg!} with ${_gameDetails!.gameData!.hostInfo!.hostNickname}.',
style: const TextStyle(
color: Colors.black,
fontFamily: 'PingFang',
fontWeight: FontWeight.w200,
fontSize: 16),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
),
Expanded(
flex: 3,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
GameData.getGameTimestamp(
_gameDetails!.gameData!.dateTime!),
style: const TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: 'PingFang',
fontWeight: FontWeight.w500,
),
),
const SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
'${_gameDetails!.gameData!.getCurrentPlayerNumber()}/${_gameDetails!.gameData!.maxPlayers}',
style: const TextStyle(
color: Colors.grey,
fontFamily: 'PingFang',
fontWeight: FontWeight.w200,
fontSize: 16),
),
const SizedBox(
width: 5,
),
const ImageIcon(
AssetImage('assets/icons/person.png'),
size: 24.0,
)
],
),
],
),
),
],
),
);
});
}
}
有什么我可以在此布局中改进以使其更好地匹配原始布局的吗?
解决方案
您可以使用 SizedBox 或 Spacer。
推荐阅读
- android - 当大小变为零时,后退按钮上的 findFragmentById 变为空白
- vue.js - 单击时如何从leafletjs折线中选择一条线?
- laravel - Laravel,faker:调用未定义的函数
- jenkins - Jenkins 管道检查基于提供的参数
- python - asyncio.Semaphore RuntimeError: Task got Future 附加到不同的循环
- apache-royale - Apache Royale 和 React、Angular、Vue 有什么区别?
- react-native - RN 0.59.5 与 RN-vector-icons 6.4.2 throwing BackAndroid 已弃用,并已从此包中删除。改用 BackHandler
- python - 使用两个列表(无 zip)创建字典 PYTHON
- reactjs - 行动后调度行动
- c# - 如何在c#中将列表项转换为多维数组?