我在小部件开始时加载指标存在问题。在我的情况下,我有一些数据异步下载到initState中,然后setState将_loading设置为false。
我想要对话,以使用Navigator操纵它的显示和消失。
错误:
P = PoissonGroup(100, np.arange(100)*Hz + 10*Hz)
初始视图
The following assertion was thrown building NotificationView(dirty, dependencies: [_LocalizationsScope-[GlobalKey#e97a5], _InheritedTheme], state: _NotificationStateView#5dbc7):
setState() or markNeedsBuild() called during build.
This Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: Overlay-[LabeledGlobalKey<OverlayState>#e85f9]
state: OverlayState#340b4(entries: [OverlayEntry#2f82c(opaque: true; maintainState: false), OverlayEntry#2187c(opaque: false; maintainState: true), OverlayEntry#50b38(opaque: false; maintainState: false), OverlayEntry#a3933(opaque: false; maintainState: true), OverlayEntry#3e2d8(opaque: false; maintainState: false), OverlayEntry#7c2c7(opaque: false; maintainState: true)])
The widget which was currently being built when the offending call was made was: NotificationView
dirty
dependencies: [_LocalizationsScope-[GlobalKey#e97a5], _InheritedTheme]
state: _NotificationStateView#5dbc7
The relevant error-causing widget was:
NotificationView lib/main.dart:51:38
When the exception was thrown, this was the stack:
#0 Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:3896:11)
#1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:3911:6)
#2 State.setState (package:flutter/src/widgets/framework.dart:1168:14)
#3 OverlayState.insertAll (package:flutter/src/widgets/overlay.dart:344:5)
#4 OverlayRoute.install (package:flutter/src/widgets/routes.dart:44:24)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ (2) Exception caught by widgets library ═══════════════════════════════════════════════════
The method 'drive' was called on null.
Receiver: null
Tried calling: drive<Color>(Instance of '_ChainedEvaluation<Color>')
The relevant error-causing widget was:
MaterialApp lib/main.dart:14:10
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ (3) Exception caught by widgets library ═══════════════════════════════════════════════════
'package:flutter/src/animation/animations.dart': Failed assertion: line 376 pos 15: 'parent != null': is not true.
The relevant error-causing widget was:
MaterialApp lib/main.dart:14:10
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ (4) Exception caught by widgets library ═══════════════════════════════════════════════════
'package:flutter/src/widgets/navigator.dart': Failed assertion: line 1782 pos 12: '!_debugLocked': is not true.
The relevant error-causing widget was:
NotificationView lib/main.dart:51:38
════════════════════════════════════════════════════════════════════════════════════════════════════
指标方法
Widget _buildView(BuildContext context) {
if (_loading) {
return showIndicator(context);
}
return Container(....);
}
答案 0 :(得分:0)
好的,我发现了问题
showIndicator (BuildContext context) {
return Dialog(
child: Center(
child: CircularProgressIndicator(),
),
);
}
showDialog
不返回小部件,而是返回Future<dynmaic>
,因此您应该使用Dialog
或任何其他小部件,而不要使用showDialog