首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >三元与TextStyle的比较

三元与TextStyle的比较
EN

Stack Overflow用户
提问于 2022-05-17 13:10:14
回答 1查看 42关注 0票数 0

我很少用三元的。我想要点提示。

基本上,如果选择的颜色是绿色,我想显示a+,如果选择的颜色是红色,则显示a+。

这是我的密码

代码语言:javascript
复制
Text( 
 [ternary] + number[math.Random().nextInt(number.length - 1)] + "%",
 style: TextStyle(
     color: predefinedColors[math.Random().nextInt(predefinedColors.length)],
     fontSize: 10.0,
     fontWeight: FontWeight.bold),
)

我所用的清单

代码语言:javascript
复制
List predefinedColors = [
  Colors.red,
  Colors.green,
];

预先感谢您的帮助

EN

回答 1

Stack Overflow用户

发布于 2022-05-17 14:00:22

代码语言:javascript
复制
  Widget build(BuildContext context) {
    return SliverToBoxAdapter(
      child: SizedBox(
          height: 139.0,
          child: ListView.builder(
              shrinkWrap: true,
              scrollDirection: Axis.horizontal,
              itemCount: 25,
              itemBuilder: (BuildContext context, int position) {
                return Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Card(
                      color:
                          Color((math.Random().nextDouble() * 0xFFFFFF).toInt())
                              .withOpacity(1.0),
                      child: const SizedBox(
                        width: 80,
                        height: 80,
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(right: 42),
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            Text(
                              names[math.Random().nextInt(names.length - 1)],
                              style: const TextStyle(
                                  color: Colors.white,
                                  fontSize: 10.0,
                                  fontWeight: FontWeight.bold),
                            ),
                            Text(
                              number[math.Random().nextInt(number.length - 1)] +
                                  "€",
                              style: const TextStyle(
                                  color: Colors.white,
                                  fontSize: 10.0,
                                  fontWeight: FontWeight.bold),
                            ),
                            Text(
                              number[math.Random().nextInt(number.length - 1)] +
                                  "%",
                              style: TextStyle(
                                  color: predefinedColors[math.Random()
                                      .nextInt(predefinedColors.length)],
                                  fontSize: 10.0,
                                  fontWeight: FontWeight.bold),
                            )
                          ]),
                    ),
                  ],
                );
              })),
    );
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72274675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档