简体   繁体   English

使用条件语句确定 TextField 在 Flutter 中如何出现

[英]use conditional statment to determine how TextField appears in Flutter

TextField (
            decoration: InputDecoration(
              hintText: 'Need extra ice or have another request?',
              contentPadding: EdgeInsets.all(10),
            ),
            //else {
            // decoration: InputDecoration(
            // hintText: Provider.of<OrderProvider>(context, listen: false).specialNotes,
            // contentPadding: EdgeInsets.all(10),
            // ),}
            onChanged: (newText) {
              Provider.of<OrderProvider>(context, listen: false)
                  .updateSpecialRequests(newText);
            },
            keyboardType: TextInputType.multiline,
            maxLines: null,
          ),

I want to make a conditional statement that determines whether the code above the commented code is read or the commented code below it gets read.我想做一个条件语句来确定是读取注释代码上方的代码还是读取它下面的注释代码。 Textfield is an array of children. Textfield 是一个子数组。 However I try to do this, it breaks my code.但是我尝试这样做,它破坏了我的代码。 The TextField invariably is no longer lit up in gold as it is when the code is working. TextField 不再像代码运行时那样亮起金色。 The online suggestions have not been working.网上的建议没有奏效。

You can use tenary operators您可以使用三元运算符

TextField (
            decoration: condition ? InputDecoration(
              hintText: 'Need extra ice or have another request?',
              contentPadding: EdgeInsets.all(10),
            ): InputDecoration(
               hintText: Provider.of<OrderProvider>.specialNotes,
               contentPadding: EdgeInsets.all(10),
             ),
            onChanged: (newText) {
              Provider.of<OrderProvider>(context, listen: false)
                  .updateSpecialRequests(newText);
            },
            keyboardType: TextInputType.multiline,
            maxLines: null,
          ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM