问题描述
当我尝试从URL加载pdf时出现错误。它显示pdf页数,但随后崩溃。
使用插件-https://pub.dev/packages/advance_pdf_viewer
════════════════════════════════════════════════════════════════════════════════════════════════════
I/Flutter (28488): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/Flutter (28488): The following assertion was thrown while rebuilding dirty elements:
I/Flutter (28488): 'package:Flutter/src/widgets/framework.dart': Failed assertion: line 4371 pos 14:
I/Flutter (28488): 'owner!._debugCurrentBuildTarget == this': is not true.
I/Flutter (28488):
I/Flutter (28488): Either the assertion indicates an error in the framework itself,or we should provide substantially
I/Flutter (28488): more information in this error message to help you determine and fix the underlying cause.
I/Flutter (28488): In either case,please report this assertion by filing a bug on GitHub:
I/Flutter (28488): https://github.com/Flutter/Flutter/issues/new?template=BUG.md
I/Flutter (28488):
I/Flutter (28488): The relevant error-causing widget was:
I/Flutter (28488): PDFViewer
I/Flutter (28488):
lib/…/panSignatureScreens/pan_screen.dart:156
I/Flutter (28488):
I/Flutter (28488): When the exception was thrown,this was the stack:
I/Flutter (28488): #2 Element.rebuild.<anonymous closure>
package:Flutter/…/widgets/framework.dart:4371
I/Flutter (28488): #3 Element.rebuild
package:Flutter/…/widgets/framework.dart:4374
I/Flutter (28488): #4 BuildOwner.buildScope
package:Flutter/…/widgets/framework.dart:2777
I/Flutter (28488): #5 WidgetsBinding.drawFrame
package:Flutter/…/widgets/binding.dart:906
I/Flutter (28488): #6 RendererBinding._handlePersistentFrameCallback
package:Flutter/…/rendering/binding.dart:309
I/Flutter (28488): #7 SchedulerBinding._invokeFrameCallback
package:Flutter/…/scheduler/binding.dart:1117
I/Flutter (28488): #8 SchedulerBinding.handleDrawFrame
package:Flutter/…/scheduler/binding.dart:1055
I/Flutter (28488): #9 SchedulerBinding._handleDrawFrame
package:Flutter/…/scheduler/binding.dart:971
I/Flutter (28488): #13 _invoke (dart:ui/hooks.dart:251:10))
I/Flutter (28488): #14 _drawFrame (dart:ui/hooks.dart:209:3))
我的用法-列内(孩子:[])
new Expanded(
child: Container(
child: PDFViewer(
document: document,),decoration: Boxdecoration(
border: Border.all(color: Colors.black),
解决方法
我遇到了同样的问题,问题是我在同一个类中调用了该类。见正文:下面。用另一个小部件替换它解决了这个问题。
class DicePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.red,appBar: AppBar(
title: Text('Dicee'),backgroundColor: Colors.red,),body: DicePage(),);
}
}
,
我刚刚遇到了一个类似的错误:
════════ Exception caught by widgets library ═══════════════════════════════════
The following StackOverflowError was thrown building Container:
Stack Overflow
The relevant error-causing widget was
Container
lib/widgets/profile_wiget.dart:9
When the exception was thrown,this was the stack
#0 new _HashMap (dart:collection-patch/collection_patch.dart)
#1 new HashMap (dart:collection-patch/collection_patch.dart:33:22)
#2 RegExp._cache (dart:core-patch/regexp_patch.dart:109:11)
#3 RegExp._cache (dart:core-patch/regexp_patch.dart)
#4 new RegExp (dart:core-patch/regexp_patch.dart:17:31)
...
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4371 pos 14: 'owner!._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was
ProfileWidget
lib/widgets/profile_wiget.dart:10
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4371 pos 14: 'owner!._debugCurrentBuildTarget == this': is not true.
The relevant error-causing widget was
Container
lib/widgets/profile_wiget.dart:9
════════════════════════════════════════════════════════════════════════════════
这可能是我遇到 stackoverflow 后的另一个原因,但我的回答有望帮助其他搜索此错误消息的人。
我的问题是我制作了一个返回自身实例的小部件(我将两个类命名为相同):
class ProfileWidget extends StatelessWidget {
final Profile profile = Profile(name: 'Someone');
@override
Widget build(BuildContext context) {
return Container(
child: (profile.isAnon) ? AnonProfileWidget() : ProfileWidget(),);
}
}
我通过简单地重命名一个类来解决它。