【问题标题】:Error ocures in onTap property while calling method调用方法时 onTap 属性出现错误
【发布时间】:2023-02-19 14:15:31
【问题描述】:
                  TextField(
                    textAlign: TextAlign.center,
                    obscureText: _obscureText,
                    onChanged: (value) {
                      //Do something with the user input.
                      password = value;
                    },
                    style: const TextStyle(color: Colors.black),
                    decoration: const InputDecoration(
                      hintText: 'Enter your Password.',
                      hintStyle: TextStyle(color: Colors.black26),
                      suffix: InkWell(
                        child: Icon(Icons.visibility),
                        onTap: _togglePasswordView,
                        //here is error in onTap
                        
                      ),
                      contentPadding:
                      EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.all(Radius.circular(32.0)),
                      ),
               

这是页面的全部代码,后缀的onTap函数有错误。错误消息显示//无效的常量值// 错误的图片在这里,

【问题讨论】:

  • suffix: InkWell( child: Icon(Icons.visibility), onTap: _togglePasswordView, //这里是onTap中的错误),
  • 你试过了吗onTap: ()=> _togglePasswordView(),

标签: flutter dart ontap


【解决方案1】:

装饰:const InputDecoration

您将输入装饰定义为常量,但在出错时它不会是常量。删除常量

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-30
    • 1970-01-01
    • 2023-03-06
    • 2015-07-21
    • 2012-02-20
    • 2014-11-18
    • 2021-08-14
    • 1970-01-01
    相关资源
    最近更新 更多