【问题标题】:argument type 'String?' can't be assigned to the parameter type 'String'参数类型“字符串?”不能分配给参数类型“字符串”
【发布时间】:2021-10-21 00:00:33
【问题描述】:

参数类型“字符串?”无法分配给参数类型“字符串”我收到此错误,但之前代码工作正常。我见过有人提出同样的问题,但我不了解根本原因。我使用的包是来自 github 的 flutter_audio_query nullsafe 版本。有人可以帮我解决这个问题。

【问题讨论】:

  • 试试这个:await player.setUrl(songInfo.uri!);

标签: flutter flutter-dependencies


【解决方案1】:

字符串?这是可为空的,您不能直接传递给非空字段。 所以像这样使用,

await player.setUrl(songInfo.uri ?? ''); // if null then empty string will be passed.

await player.setUrl(songInfo.uri!); // this is you saying that it won't be null.

【讨论】:

    猜你喜欢
    • 2021-10-13
    • 2021-09-04
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 2021-08-02
    相关资源
    最近更新 更多