首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能无条件地调用该函数,因为它可以是“null”。ZStack.clip()

不能无条件地调用该函数,因为它可以是“null”。ZStack.clip()
EN

Stack Overflow用户
提问于 2022-12-02 18:41:14
回答 1查看 24关注 0票数 0

这段代码来自于预空安全版本的颤振。它使用VelocityX,我知道它有点便宜,但是我试图通过修改它来使它工作。

代码语言:javascript
复制
"radios": [
  {
    "id": 1,
    "name": "92.7",
    "tagline": "Suno Sunao, Life Banao!",
    "color": "0xffa11431",
    "desc": "The chills you get when you listen to music, is mostly caused by the brain releasing dopamine while anticipating the peak moment of a song.",
    "url": "http://sc-bb.1.fm:8017/;",
    "icon": "https://mytuner.global.ssl.fastly.net/media/tvos_radios/m8afyszryaqt.png",
    "image": "https://mir-s3-cdn-cf.behance.net/project_modules/max_1200/b5df4c18876369.562d0d4bd94cf.jpg",
    "lang": "Hindi",
    "category": "pop",
    "disliked": false,
    "order": 1
  },
...
]
代码语言:javascript
复制
final rad = radios![index];
ZStack? Z = ZStack([
  Positioned(
    top: 0.0,
    right: 0.0,
    child: VxBox(
      child:  rad.category.text.uppercase.white.make().p16(),
    ).height(40).color(Colors.black).alignCenter.withRounded(value: 10.0).make(),

  ),

  Align(
    alignment: Alignment.bottomCenter,
    child: VStack([
      rad.name.text.xl3.white.bold.make(),
      5.heightBox,
      rad.tagline.text.sm.white.semiBold.make(),
    ],
      crossAlignment: CrossAxisAlignment.center,
    ),
  ),
  Align(
    alignment: Alignment.center,
    child: [const Icon(
      CupertinoIcons.play_circle,
      color: Colors.white,
    ),
      10.heightBox,
      "Double tap to play".text.gray300.make()
    ].vStack(),
  ),
]).clip(Clip.antiAlias);

除了最后一行(即.clip(Clip.antiAlias) )之外,一切都很正常。

它给出了以下错误:错误

如果我删除.clip(Clip.antiAlias),它就能正常工作。

我以前解决了一个类似的错误

代码语言:javascript
复制
itemCount: radios?.length ?? 0,

而且起作用了。

但是,ZStack Z1 = Z?.clip(Clip.antiAlias) ?? Z,其中Z没有.clip()方法,不起作用。甚至!空检查不起作用。

有什么解决办法吗?或者我错过了什么最佳实践?

EN

回答 1

Stack Overflow用户

发布于 2022-12-02 19:15:29

请加!空检查操作符在.clip()之前

您的问题的解决方案是->

代码语言:javascript
复制
ZStack Z1 = Z!.clip(Clip.antiAlias) ?? Z

如果对象返回null,则Z必须是其他对象。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74660180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档