繁体   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,
          ),

我想做一个条件语句来确定是读取注释代码上方的代码还是读取它下面的注释代码。 Textfield 是一个子数组。 但是我尝试这样做,它破坏了我的代码。 TextField 不再像代码运行时那样亮起金色。 网上的建议没有奏效。

您可以使用三元运算符

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