最近我一直在尝试更新个人资料。 所以这是场景 主页=>抽屉=>配置文件=>主页。 当我返回时,这就是我得到的错误。
⡿flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building BlocListener<HomeBloc, HomeState>(dirty, state:
flutter: _BlocListenerBaseState<HomeBloc, HomeState>#4a7df):
flutter: A build function returned null.
flutter: The offending widget is:
flutter: BlocListener<HomeBloc, HomeState>
flutter: Build functions must never return null.
flutter: To return an empty space that causes the building widget to fill available room, return
flutter: "Container()". To return an empty space that takes as little room as possible, return
flutter: "Container(width: 0.0, height: 0.0)".
flutter:
flutter: The relevant error-causing widget was:
flutter: BlocListener<HomeBloc, HomeState>
flutter: file:///Users/macbook/Documents/development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_bloc-6.0.6/lib/src/bloc_builder.dart:148:12
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 debugWidgetBuilderValue.<anonymous closure> (package:flutter/src/widgets/debug.dart:302:7)
flutter: #1 debugWidgetBuilderValue (package:flutter/src/widgets/debug.dart:323:4)
flutter: #2 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4632:7)
flutter: #3 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #4 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #5 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #6 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #7 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #8 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #9 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #10 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #11 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #13 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #14 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5)
flutter: #15 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #16 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #17 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #18 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #19 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #20 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #21 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #22 _InheritedProviderScopeElement.performRebuild (package:provider/src/inherited_provider.dart:426:11)
flutter: #23 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #24 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
flutter: #25 _InheritedProviderScopeElement.update (package:provider/src/inherited_provider.dart:446:11)
flutter: #26 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #27 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #28 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #29 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5)
flutter: #30 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #31 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #32 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #33 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5)
flutter: #34 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #35 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
flutter: #36 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #37 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #38 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #39 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5)
flutter: #40 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #41 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
flutter: #42 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #43 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
flutter: #44 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #45 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #46 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #47 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #48 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #49 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #50 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5647:32)
flutter: #51 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6246:17)
flutter: #52 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #53 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #54 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #55 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #56 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #57 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #58 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
flutter: #59 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #60 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #61 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #62 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #63 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #64 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #65 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
flutter: #66 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #67 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #68 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #69 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #70 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #71 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #72 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
flutter: #73 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #74 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #75 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #76 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #77 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #78 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #79 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #80 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #81 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5)
flutter: #82 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #83 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #84 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #85 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #86 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #87 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #88 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
flutter: #89 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #90 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #91 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #92 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
flutter: #93 _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:183:11)
flutter: #94 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #95 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
flutter: #96 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #97 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #98 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #99 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #100 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #101 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #102 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #103 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #104 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
flutter: #105 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #106 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #107 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #108 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #109 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
flutter: #110 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #111 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #112 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #113 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5)
flutter: #114 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #115 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
flutter: #116 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #117 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #118 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #119 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
flutter: #120 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
flutter: #121 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
flutter: #122 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
flutter: #123 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
flutter: #124 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2730:33)
flutter: #125 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:913:20)
flutter: #126 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:302:5)
flutter: #127 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
flutter: #128 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1055:9)
flutter: #129 SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:864:7)
flutter: (elided 4 frames from class _RawReceivePortImpl, class _Timer, and dart:async-patch)
flutter:
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
这是我的BlocConsumer代码:
BlocConsumer<PrivateprofileBloc, PrivateprofileState>(
builder: (context, state) {
if (state is PrivateprofileInitial) {
return bodyBuild();
} else if (state is PrivateprofilePictureUpdate) {
this.user = state.user;
return bodyBuild();
} else if (state is PrivateprofileUpdate) {
this.user = state.user;
return bodyBuild();
} else if (state is PrivateprofileReturn) {
return BlocProvider(
create: (context) => HomeBloc(state.user),
child: HomePage(state.user));
}
},
listener: (context, state) {},
)
知道为什么吗?数据得到更新,我用更新后的数据再次返回主页,但是我在终端机中收到该错误。
答案 0 :(得分:0)
因为在BlocBuilder的“ else”情况下没有返回Widget。
只需在“ BlocBuilder”中返回空容器即可。
据我所知,“侦听器”返回“无效”,您无需返回任何内容。
BlocConsumer<HomeBloc, HomeState>(
builder: (context, state) {
if (state is HomeInitial) {
return buildBody();
} else if (state is HomeUpdatedUser) {
widget._user = state.user;
return buildBody();
}
return Container();
},
);