Flutter 如何在小部件中设置条件?

Flutter 如何在小部件中设置条件?,flutter,Flutter,我想设置一个条件,如果(value==7){Textspan(text:“JACKPOT:+j.j7)}或者{Textspan(text:“JACKPOT:+j.j14}在这段写有JACKPOT的代码中,这段代码在futurebuilder中执行: Container( margin: EdgeInsets

我想设置一个条件,如果(value==7){Textspan(text:“JACKPOT:+j.j7)}或者{Textspan(text:“JACKPOT:+j.j14}在这段写有JACKPOT的代码中,这段代码在futurebuilder中执行:

Container(
                                                    margin: EdgeInsets
                                                        .only(
                                                        bottom: 10),
                                                    child: RichText(
                                                      text: TextSpan(
                                                        children: [
                                                          TextSpan(
                                                              text: "JACKPOT : "  +
                                                                  " ",
                                                              style: TextStyle(
                                                                  fontSize: 20,
                                                                  fontWeight: FontWeight
                                                                      .w800,
                                                                  color: Colors
                                                                      .black)
                                                          ),
                                                          WidgetSpan(
                                                              child: Icon(
                                                                  FontAwesomeIcons
                                                                      .euroSign,
                                                                  color: Colors
                                                                      .amber[900],
                                                                  size: 20)
                                                          ),

为此使用三元运算符

// ......
text: "JACKPOT : "+ value==7 ? j.j7.toString() : j.j14.toString()
// ........
// Given j7 & j14 are int

我这样做但不起作用:TextSpan(text:“JACKPOT:”+values[index].nb_match==7?j.j7:j.j14+““它说”错误:参数类型“int”不能分配给参数类型“String”。(参数类型在[gameapp]lib\grill\u lotosport.dart:191处不可分配)我已经更新了我的答案。请检查。错误是因为j7和j14的类型为int。我们需要在连接之前将其转换为字符串。您需要在代码中添加更多缩进,这样移动设备上的ppl就不会关心您的问题。