gpt4 book ai didi

flutter - 如何省略第二个条件

转载 作者:行者123 更新时间:2023-12-03 04:09:30 25 4
gpt4 key购买 nike

如何在条件语句中省略第二个条件?

    return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
message != null
? Padding(
padding: const EdgeInsets.all(24.0),
child: Text(message),
)
: null, // how to omit second condition?
],
);

当第二个条件为空我得到

════════ Exception caught by widgets library ════════ The following assertion was thrown building ExportData(dirty, state: _ExportDataState#e723d): Column's children must not contain any null values, but a null value was found at index 4

最佳答案

我更喜欢SizedBox而不是Container

return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
message != null
? Padding(
padding: const EdgeInsets.all(24.0),
child: Text(message),
)
: SizedBox(),
],
);

关于flutter - 如何省略第二个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61571193/

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