微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

高级 PDF 查看器:断言失败:第 4263 行 pos 14:'owner!._debugCurrentBuildTarget == this':不是真的

如何解决高级 PDF 查看器:断言失败:第 4263 行 pos 14:'owner!._debugCurrentBuildTarget == this':不是真的

当我尝试从 URL 加载 pdf 时出现错误。 它显示pdf的页数,但屏幕上出现错误

Screenshot of error

Using plugin - https://pub.dev/packages/advance_pdf_viewer

Logcat:

======== Exception caught by widgets library 

=======================================================
The following _CastError was thrown building NotificationListener<KeepAliveNotification>:
Null check operator used on a null value

The relevant error-causing widget was: 
  PDFViewer file:///D:/GST%20with%20GT/gst_with_gt/lib/screens/pdfview.dart:70:19
When the exception was thrown,this was the stack: 
#0      _pdfpageState._repaint (package:advance_pdf_viewer/src/page.dart:54:45)
#1      _pdfpageState.didChangeDependencies (package:advance_pdf_viewer/src/page.dart:42:5)
#2      StatefulElement._firstBuild (package:Flutter/src/widgets/framework.dart:4725:11)
#3      ComponentElement.mount (package:Flutter/src/widgets/framework.dart:4541:5)
#4      Element.inflateWidget (package:Flutter/src/widgets/framework.dart:3603:14)
...
====================================================================================================

======== Exception caught by widgets library =======================================================
The following assertion was thrown building SliverFillViewport:
'package:Flutter/src/rendering/sliver_multi_Box_adaptor.dart': Failed assertion: line 258 pos 16: 'child == null || indexOf(child) > index': is not true.


Either the assertion indicates an error in the framework itself,or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case,please report this assertion by filing a bug on GitHub:
  https://github.com/Flutter/Flutter/issues/new?template=2_bug.md

The relevant error-causing widget was: 
  PDFViewer file:///D:/GST%20with%20GT/gst_with_gt/lib/screens/pdfview.dart:70:19
When the exception was thrown,this was the stack: 
#2      RenderSliverMultiBoxAdaptor._debugVerifyChildOrder (package:Flutter/src/rendering/sliver_multi_Box_adaptor.dart:258:16)
#3      RenderSliverMultiBoxAdaptor.debugChildIntegrityEnabled=.<anonymous closure> (package:Flutter/src/rendering/sliver_multi_Box_adaptor.dart:233:14)
#4      RenderSliverMultiBoxAdaptor.debugChildIntegrityEnabled= (package:Flutter/src/rendering/sliver_multi_Box_adaptor.dart:235:6)
#5      SliverMultiBoxAdaptorElement.performRebuild (package:Flutter/src/widgets/sliver.dart:1208:20)
#6      SliverMultiBoxAdaptorElement.update (package:Flutter/src/widgets/sliver.dart:1124:7)
...
====================================================================================================

======== Exception caught by widgets library =======================================================
The following assertion was thrown building RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#411e6](state: RawGestureDetectorState#4acaf(gestures: <none>,behavior: opaque)):
A RenderViewport expected a child of type RenderSliver but received a child of type RenderErrorBox.

RenderObjects expect specific types of children because they coordinate with their children during layout and paint. For example,a RenderSliver cannot be the child of a RenderBox because a RenderSliver does not understand the RenderBox layout protocol.
The RenderViewport that expected a RenderSliver child was created by: Viewport ← IgnorePointer-[GlobalKey#e5bfe] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#411e6] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#3ad9e] ← RepaintBoundary ← CustomPaint ← RepaintBoundary ← ⋯
The RenderErrorBox that did not match the expected child type was created by: ErrorWidget-[#87a59] ← SliverFillViewport ← Viewport ← IgnorePointer-[GlobalKey#e5bfe] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#411e6] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#3ad9e] ← RepaintBoundary ← ⋯
The relevant error-causing widget was: 
  PDFViewer file:///D:/GST%20with%20GT/gst_with_gt/lib/screens/pdfview.dart:70:19
When the exception was thrown,this was the stack: 
#0      ContainerRenderObjectMixin.debugValidateChild.<anonymous closure> (package:Flutter/src/rendering/object.dart:3134:9)
#1      ContainerRenderObjectMixin.debugValidateChild (package:Flutter/src/rendering/object.dart:3161:6)
#2      MultiChildRenderObjectElement.insertRenderObjectChild (package:Flutter/src/widgets/framework.dart:6127:25)
#3      RenderObjectElement.attachRenderObject (package:Flutter/src/widgets/framework.dart:5737:35)
#4      RenderObjectElement.mount (package:Flutter/src/widgets/framework.dart:5433:5)
...
====================================================================================================

======== Exception caught by widgets library =======================================================
The following assertion was thrown building _ScrollableScope:
'package:Flutter/src/widgets/framework.dart': Failed assertion: line 4263 pos 14: 'owner!._debugCurrentBuildTarget == this': is not true.


Either the assertion indicates an error in the framework itself,this was the stack: 
#2      Element.rebuild.<anonymous closure> (package:Flutter/src/widgets/framework.dart:4263:14)
#3      Element.rebuild (package:Flutter/src/widgets/framework.dart:4266:6)
#4      StatefulElement.update (package:Flutter/src/widgets/framework.dart:4771:5)
#5      Element.updateChild (package:Flutter/src/widgets/framework.dart:3345:15)
#6      SingleChildRenderObjectElement.update (package:Flutter/src/widgets/framework.dart:6057:14)
...

这里,我的代码

class PdfViewers extends StatefulWidget {

  @override
  PdfVieweRSState createState() => PdfVieweRSState();
}

    class PdfVieweRSState extends State<PdfViewers> {
      bool _isLoadings = true;
      PDFDocument docs;
    
    
      @override
      void initState() {
        Timer(
          Duration(seconds: 1),() => loadUrl(),);
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
            backgroundColor: Colors.grey[100],appBar: AppBar(
              elevation: 0,backgroundColor: Colors.grey[100],actions: [
                
                IconButton(
                    icon: Icon(
                      Icons.share_rounded,color: Color(0xff4f2e7f),),onpressed: () async {}),],title: Text(
                'PDF Article',softWrap: true,style: TextStyle(color: Color(0xff4f2e7f)),leading: IconButton(
                  onpressed: () {
                    Navigator.pop(context,true);
                  },icon: Icon(Icons.arrow_back_outlined,color: Color(0xff4f2e7f))),body: Center(
                child: _isLoadings
                    ? Container(child: CircularProgressIndicator())
                    : PDFViewer(document: docs)));
      }
    
      Future<void> loadUrl() async {
        setState(() {
          _isLoadings = true;
        });
    
        docs= await PDFDocument.fromURL(
            'https://gstwithgt.fivestake.com/uploads/topics/16254191793470.pdf');
    
        setState(() {
          _isLoadings = false;
        });
      }
    


}

我尝试并搜索了许多教程和示例,但没有一个我有用。所以我在这里发布了问题。

最重要的是,当我在另一个项目中粘贴相同的代码时,它工作正常。我不知道问题出在哪里..我从前两天开始试图解决这个错误..

解决方法

我也遇到了同样的问题。 您可以在此处找到完整的讨论:https://github.com/lohanidamodar/pdf_viewer/issues/62

似乎在第一次尝试打开文件时,它从这里返回 null:

var data = await _channel .invokeMethod('getPage',{'filePath': _filePath,'pageNumber': page});

(来自 document.dart 文件)

有趣的是,在我重新打开应用后一切正常

这个补丁为我解决了这个异常:

我注意到在我重新打开应用程序(解决了问题)并尝试打开 PDF 之前,我收到了这个异常:

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.app.Activity.getResources()' on a null object reference

但是当我重新打开应用程序并且一切正常时,此异常消失了。因此,我在此存储库问题中查找了此异常并遇到了此修复程序:

https://github.com/lohanidamodar/pdf_viewer/issues/45

实施 RasyidMF 解决方案后,PDF 正确打开。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。