【发布时间】:2021-03-10 19:11:05
【问题描述】:
我完全是 Flutter 的初学者。我正在开发一个应用程序,它显示本地存储中的 pdf 并将其存储在本地数据库中。当我在模拟器中运行时它工作正常,但在真实设备中运行时它显示错误我使用 Advance pdf 查看器插件 我还创建了 proguard-rues.pro 文件。有谁能帮我解决这个问题。
这是我的 pdf 获取代码
FilePickerResult pdf = await FilePicker.platform
.pickFiles(type: FileType.custom, allowedExtensions: ['pdf']);
_pdf = File(pdf.files.single.path);
doc = await PDFDocument.fromFile(_pdf);
MyPdf 文档查看器代码
Container(
width: 120,
height: 120,
margin: EdgeInsets.all(10.0),
child: PDFViewer(
document: doc,
),
)
我的 proguard rules.pro 文件
-keep class com.shockwave.**
-keepclassmembers class com.shockwave.** { *; }
我的 android 构建 gradle 文件
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
我的安卓清单文件
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
<application
android:requestLegacyExternalStorage="true"
在真机运行时出现错误提示
D/FilePickerUtils(22253): Allowed file extensions mimes: [application/pdf]
D/FilePickerDelegate(22253): Selected type */*
I/SurfaceView(22253): updateWindow -- onWindowVisibilityChanged, visibility = 8, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 Changes: creating=false format=false size=false visible=true left=false top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceSizeChanged=false mVisible=true mRequestedVisible=false, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 Cur surface: Surface(name=null)/@0xce7fd99, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 New surface: Surface(name=null)/@0xb61c85e, vis=false, frame=Rect(0, 0 - 480, 854), this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 visibleChanged -- surfaceDestroyed, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): surfaceDestroyed callback +, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
D/GraphicBuffer(22253): register, handle(0x86399440) (w:480 h:854 s:480 f:0x1 u:0x000b00)
D/Surface (22253): Surface::disconnect(this=0x9038d700,api=1)
D/GraphicBuffer(22253): unregister, handle(0x86398300) (w:480 h:854 s:480 f:0x1 u:0x000b00)
D/GraphicBuffer(22253): unregister, handle(0x86398480) (w:480 h:854 s:480 f:0x1 u:0x000b00)
D/GraphicBuffer(22253): unregister, handle(0x86399440) (w:480 h:854 s:480 f:0x1 u:0x000b00)
D/Surface (22253): Surface::disconnect(this=0x9038d700,api=1)
I/SurfaceView(22253): surfaceDestroyed callback -, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
V/SurfaceView(22253): Layout: x=0 y=0 w=480 h=854, frame=Rect(0, 0 - 480, 854), this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
D/SurfaceView(22253): 156878148 windowPositionLostRT RT, frameNr = 0
D/Surface (22253): Surface::disconnect(this=0x9038fa00,api=1)
D/GraphicBuffer(22253): unregister, handle(0x9172aec0) (w:480 h:854 s:480 f:0x1 u:0x000b00)
D/GraphicBuffer(22253): unregister, handle(0x9172b040) (w:480 h:854 s:480 f:0x1 u:0x000b00)
D/GraphicBuffer(22253): unregister, handle(0x9172af80) (w:480 h:854 s:480 f:0x1 u:0x000b00)
D/Surface (22253): Surface::disconnect(this=0x9038fa00,api=1)
V/PhoneWindow(22253): DecorView setVisiblity: visibility = 4, Parent = ViewRoot{bfd9ce3 com.example.detailscollector/com.example.detailscollector.MainActivity,ident = 0}, this = DecorView@be0ade5[MainActivity]
I/SurfaceView(22253): updateWindow -- onWindowVisibilityChanged, visibility = 4, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/FilePickerUtils(22253): Caching from URI: content://com.android.providers.downloads.documents/document/3389
V/PhoneWindow(22253): DecorView setVisiblity: visibility = 0, Parent = ViewRoot{bfd9ce3 com.example.detailscollector/com.example.detailscollector.MainActivity,ident = 0}, this = DecorView@be0ade5[MainActivity]
D/ActivityThread(22253): isAppLocked r.intent.getComponent().getPackageName() = com.example.detailscollector
D/ActivityThread(22253): isAppLocked r.intent.getComponent() = ComponentInfo{com.example.detailscollector/com.example.detailscollector.MainActivity}
I/SurfaceView(22253): updateWindow -- onWindowVisibilityChanged, visibility = 0, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 Changes: creating=false format=false size=false visible=true left=false top=false mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceSizeChanged=false mVisible=false mRequestedVisible=true, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 Cur surface: Surface(name=null)/@0xce7fd99, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 New surface: Surface(name=null)/@0xb61c85e, vis=true, frame=Rect(0, 0 - 480, 854), this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 visibleChanged -- surfaceCreated, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): surfaceCreated callback +, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
D/Surface (22253): Surface::connect(this=0x9038fa00,api=1)
W/libEGL (22253): [ANDROID_RECORDABLE] format: 1
D/mali_winsys(22253): EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000
I/SurfaceView(22253): surfaceCreated callback -, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 surfaceChanged -- format=4 w=480 h=854, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): surfaceChanged callback +, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): surfaceChanged callback -, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 surfaceRedrawNeeded, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
I/SurfaceView(22253): 156878148 finishedDrawing, this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
V/SurfaceView(22253): Layout: x=0 y=0 w=480 h=854, frame=Rect(0, 0 - 480, 854), this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
D/OpenGLRenderer(22253): CanvasContext() 0x90237000 initialize window=0x9038f300, title=com.example.detailscollector/com.example.detailscollector.MainActivity
D/Surface (22253): Surface::connect(this=0x9038f300,api=1)
W/libEGL (22253): [ANDROID_RECORDABLE] format: 1
V/InputMethodManager(22253): onWindowFocus: io.flutter.embedding.android.FlutterView{bebe62d VFE...... .F...... 0,0-480,854} softInputMode=16 first=true flags=#81810100
D/mali_winsys(22253): EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000
I/SurfaceView(22253): Punch a hole(dispatchDraw), this = io.flutter.embedding.android.FlutterSurfaceView{959c544 V.E...... ........ 0,0-480,854}
D/SurfaceView(22253): 156878148 updateWindowPosition RT, frameNr = 1, postion = [0, 0, 480, 854]
D/GraphicBuffer(22253): register, handle(0x9172af80) (w:480 h:854 s:480 f:0x1 u:0x000b00)
D/GraphicBuffer(22253): register, handle(0x9172b4c0) (w:480 h:854 s:480 f:0x1 u:0x000b00)
D/GraphicBuffer(22253): register, handle(0x9172b040) (w:480 h:854 s:480 f:0x1 u:0x000b00)
D/FilePickerUtils(22253): File loaded and cached at:/data/user/0/com.example.detailscollector/cache/file_picker/96842
D/FilePickerDelegate(22253): File path:[com.mr.flutter.plugin.filepicker.FileInfo@a9b953c]
I/flutter (22253): pdf file
I/flutter (22253): found
I/art (22253): Enter while loop.
I/art (22253): Background sticky concurrent mark sweep GC freed 15207(1053KB) AllocSpace objects, 5(100KB) LOS objects, 0% free, 23MB/23MB, paused 1.951ms total 108.250ms
I/art (22253): Enter while loop.
I/System.out(22253): length=5; regionStart=0; regionLength=-1
W/System.err(22253): java.lang.StringIndexOutOfBoundsException: length=5; regionStart=0; regionLength=-1
W/System.err(22253): at java.lang.String.substring(String.java:1931)
W/System.err(22253): at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin.getFileNameFromPath(FlutterPluginPdfViewerPlugin.java:125)
W/System.err(22253): at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin.createTempPreview(FlutterPluginPdfViewerPlugin.java:130)
W/System.err(22253): at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin.getPage(FlutterPluginPdfViewerPlugin.java:170)
W/System.err(22253): at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin.access$100(FlutterPluginPdfViewerPlugin.java:29)
W/System.err(22253): at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin$1.run(FlutterPluginPdfViewerPlugin.java:70)
W/System.err(22253): at android.os.Handler.handleCallback(Handler.java:836)
W/System.err(22253): at android.os.Handler.dispatchMessage(Handler.java:103)
W/System.err(22253): at android.os.Looper.loop(Looper.java:203)
W/System.err(22253): at android.os.HandlerThread.run(HandlerThread.java:61)
D/GraphicBuffer(22253): register, handle(0x9172b580) (w:480 h:854 s:480 f:0x1 u:0x000b00)
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following ArgumentError was thrown building NotificationListener<KeepAliveNotification>:
Invalid argument(s) (path): Must not be null
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
When the exception was thrown, this was the stack:
#0 ArgumentError.checkNotNull (dart:core/errors.dart:194:27)
#1 _File._checkNotNull (dart:io/file_impl.dart:641:19)
#2 new _File (dart:io/file_impl.dart:205:17)
#3 new File (dart:io/file.dart:250:18)
#4 _PDFPageState._repaint (package:advance_pdf_viewer/src/page.dart:47:26)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 259 pos 16: 'child == null || indexOf(child) > index': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
A RenderViewport expected a child of type RenderSliver but received a child of type RenderErrorBox.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was:
PDFViewer file:///C:/Users/Dell/Desktop/New%20folder/12-11-2020-detailscollector/lib/create.dart:200:40
════════════════════════════════════════════════════════════════════════════════════════════════════
【问题讨论】: