首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于advance_pdf_viewer和firebase_storage的颤振依赖问题

基于advance_pdf_viewer和firebase_storage的颤振依赖问题
EN

Stack Overflow用户
提问于 2021-05-29 08:01:59
回答 1查看 1.3K关注 0票数 4

当使用advance_pdf_viewer和firebase_storage包时,无法将应用程序复杂化。起初它的工作很好,但后来它的版本发生了变化,我不知道匹配的确切版本。

Publicspec.yaml文件

代码语言:javascript
复制
  cupertino_icons: ^1.0.3
  flutter_svg: ^0.22.0 # help us to use SVG in our app
  provider: ^5.0.0 # for State management
  getwidget: ^2.0.2
  shared_preferences: ^2.0.5
  firebase_auth: ^1.0.1
  firebase_core: ^1.0.2
  cloud_firestore: ^1.0.3
  firebase_storage: ^8.0.1
  advance_pdf_viewer:
  date_time_picker: ^2.0.0
  file_picker:
  intl: ^0.17.0
  path: ^1.8.0
  http:

错误消息

代码语言:javascript
复制
Running "flutter pub get" in appT...
Launching lib/main.dart on SDKPhone in debug mode...
Running Gradle task 'assembleDebug'...
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
../../flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart:64:14: Error: The class 'File' is abstract and can't be instantiated.
      file = File("${dir.path}/file.pdf");
             ^^^^
../../flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart:72:26: Error: Non-nullable variable 'file' must be assigned before it can be used.
    document._filePath = file.path;
                         ^^^^
../../flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart:75:58: Error: Non-nullable variable 'file' must be assigned before it can be used.
          .invokeMethod('getNumberOfPages', {'filePath': file.path});
                                                         ^^^^


FAILURE: Build failed with an exception.

* Where:
Script '/home/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1035

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/home/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 48s
Exception: Gradle task assembleDebug failed with exit code 1
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-01 15:29:20

#这很管用

以详细的方式从上面的链接答案。

编辑/flutter/.pub-cache/hosted/pub.dartlang.org/advance_pdf_viewer-2.0.0/lib/src/document.dart

代码语言:javascript
复制
//edit the import line like this
//import 'dart:io'; - > import 'dart:io' as io; : line 2
import 'dart:io' as io;
....
....
....

static Future fromAsset(String asset) async {
    io.File file; // Edited
    try {
        var dir = await getApplicationDocumentsDirectory();
        file = io.File("${dir.path}/file.pdf"); // Edited
        var data = await rootBundle.load(asset);
        var bytes = data.buffer.asUint8List();
        await file.writeAsBytes(bytes, flush: true);
    } catch (e) {
        throw Exception('Error parsing asset file!');
    }
    PDFDocument document = PDFDocument();
    document._filePath = file.path;
    try {
        var pageCount = await _channel
        .invokeMethod('getNumberOfPages', {'filePath': file.path});
        document.count = document.count = int.parse(pageCount);
    } catch (e) {
        throw Exception('Error reading PDF!');
    }
    return document;
}

解决方案:

将包导入为"io“,并只在"fromAsset”函数中更改,将类(文件)调用为"io.File“,这样它就能正常工作。

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

https://stackoverflow.com/questions/67749105

复制
相关文章

相似问题

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