【问题标题】:NoSuchMethodError: The getter 'path' was called on null. Receiver: null Tried calling: pathNoSuchMethodError:在 null 上调用了 getter 'path'。接收方:null 尝试调用:路径
【发布时间】:2020-11-01 14:18:40
【问题描述】:

当我将 pdf URL 值传递给它时,内置关键字“path”会出现错误,它似乎为空?

loadPdf(String pdfPath) async {
    setState(() => _isLoading = true);

    var fileName = pdfPath.split('/').last;
    
    var localFileUrl = (await Directory(CacheManager.getInstance().appDocumentDir.path +'/'+"realpro"+"/").create(recursive: true)).path +fileName;
    
    if (await CacheManager.getInstance().checkFileExist(localFileUrl)) {
      document = await PDFDocument.fromAsset(localFileUrl);
      print(document);
      setState(() {
        _isLoading = false;
      });
    } else {
      document = await PDFDocument.fromURL(pdfPath);
      print(document);
      setState(() {
        _isLoading = false;
      });
    }
}

【问题讨论】:

标签: android ios flutter dart flutter-layout


【解决方案1】:

在 null 上调用了 getter 'path'。

错误意味着您正在为其编写object.path 的对象是null。您可以像这样使用?. 运算符:object?.something,相当于:

object!=null ? object.something : null

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-27
    • 2021-06-03
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 2020-06-11
    • 2021-09-07
    • 2023-03-20
    相关资源
    最近更新 更多