首页 > 其他分享 >Invalid constant value.问题

Invalid constant value.问题

时间:2024-01-02 19:32:54浏览次数:451  
标签:const orientation Invalid value RecordDay constant null 构造函数

Invalid constant value.问题

在你的 _RecordDay 类中,你定义了一个 const 构造函数:

const _RecordDay(this.orientation);

但是在 build 方法中,你使用了这个构造函数:

RecordDay(orientation == Orientation.portrait),

这里的问题是,你在构造函数中使用了 const,但是在实际调用构造函数时,传递的参数使用了表达式 orientation == Orientation.portrait,这是一个非常量表达式,导致整个实例不再是 const

要解决这个问题,你可以考虑在构造函数中移除 const

_RecordDay(this.orientation);

然后在使用时,不再需要 const

RecordDay(orientation == Orientation.portrait),

这样就能避免 "Invalid constant value." 的错误。


如果你遇到了"A value of type 'Null' can't be assigned to a parameter of type 'bool' in a const constructor."的错误,说明在使用 const 构造函数时,传递的参数可能为 null

在 Dart 中,const 构造函数要求传递的参数不能为 null。如果你想在构造函数中接收 null 值,应该去掉构造函数前的 const 关键字。

以下是一个不使用 const 的例子:

class _RecordDay extends ConsumerWidget {
  final bool? orientation;

  // 构造函数
  const _RecordDay({required this.orientation});  

  // ... 其他部分
}

这里 bool? 表示 orientation 可以为 null。如果你不确定传递的参数是否为 null,可以使用这种方式来处理。


标签:const,orientation,Invalid,value,RecordDay,constant,null,构造函数
From: https://blog.51cto.com/u_16392501/9072396

相关文章

  • Mapped Statements collection does not contain value for
    前倾概要:在测试Springabtch分区的过程中,我在本地使用mybatis-plus的时候出现了下面的问题:org.mybatis.spring.MyBatisSystemException:nestedexceptionisorg.apache.ibatis.exceptions.PersistenceException:###Errorqueryingdatabase.Cause:java.lang.IllegalArgumen......
  • 流畅的Python纸牌:rank_value * len(suit_value)为什么要乘以4
    用点数(rank_value )和花色(suits_values)两个因素对每张牌排序,每张牌都有不同的数值returnrank_value*len(suits_values)+suits_values[card.suit]其中:ranks=[str(n)forninrange(2,11)]+list('JQKA')suits_values=dict(zip(suits,[3,1,0,2]))*len(suits_......
  • cache操作:clean、invalidate与flush的含义
    前言本文试图搞清楚cache几个操作:clean、invalidate与flush的含义。由于只用过ARM和RISC-V,所以是从ARM和RISC-V的角度来说明。 cachelinecacheline是cache的基本访问单元。cacheline一般都会包含valid和dirty两个状态位,如下图的v和d。valid位表示当前cacheline的内容是......
  • insert into select 遇到的一个坑 Truncated incorrect DOUBLE value
    INSERTINTOa(aax,aaz)(SELECTaax,aazFROMbWHERExIN(1,2,3));类似一个这种数据迁移的sql如果用了where条件请在条件上完全遵从数据格式如果偷懒直接输入数字类型的1,2,3的话就会报错runcatedincorrectDOUBLEvalue......
  • Failed to convert value of type 'java.lang.String' to required type 'java.lang.L
    我测试的是一个接口接口里面没有任何参数怎么会报参数类型转换错误呢mad!!!!! 第二个接口就很蒙测了好久都是这个问题而且你打debug它不进这个接口并且你执行其他写好的接口它还是会报同样的错。。。。。。。。。。。。。。其实就是你代码的位置写错了应该写在pc......
  • 【HMS Core】{"sub_error":20003,"error_description":"parameter invalid",&
    ​ 【问题描述】离线推送服务端报错{"sub_error":20003,"error_description":"parameterinvalid","error":1101} 【解决方案】错误码1101代表是client_id在系统中不存在,需要检查一下APPID是否配置正确​​......
  • 【五期李伟平】CCF-A(S&P'20)The Value of Collaboration in Convex Machine Learning w
    NanW.,etal.“TheValueofCollaborationinConvexMachineLearningwithDifferentialPrivacy.”2020IEEESymposiumonSecurityandPrivacy.304-317.  联邦学习场景中,在适应度函数平滑、强凸、利普斯特连续的条件下,估算各客户端使用不同隐私预算时最终全局模......
  • Python - pandas 报错:ValueError: 'HIS_批准文号' is both an index level and a colu
    问题描述file:[Terminal]ValueError:'HIS_批准文号'isbothanindexlevelandacolumnlabel,whichisambiguous.ValueError:cannotinsert招采_批准文号,alreadyexists有这两个错误,使用函数merge合并的时候出现第一个错误,将两个DataFrame的索引reset_index......
  • 讲解'utf-8' codec can't decode byte 0xb6 in position 34: invalid start byte
    讲解'utf-8'codeccan'tdecodebyte0xb6inposition34:invalidstartbyte在编程过程中,我们经常会遇到各种编码和解码的问题。其中一个常见的错误是'utf-8'codeccan'tdecodebyte0xb6inposition34:invalidstartbyte。这个错误表示在使用utf-8编码解码时,无法解......
  • Java Spring Boot 配置读取进阶篇-@ConfigurationProperties && @Value
    之前我们学习了在SpringBoot如何读取application.properties/application.yaml配置文件的配置信息,在上文中我们主要是简单地实践了些简单的设置,这次我们带着同样的问题,如果配置更加复杂,我们的配置读取又应该怎么处理呢。本文的学习主要基于SpringBoot自带的库来解析配置,......