Skip to content

BrnPopupListWindow.showPopListWindow 调用时会报错 'dependOnInheritedWidgetOfExactType<_ViewScope>() or dependOnInheritedElement() was called before _BrnPopupWindowState.initState() completed.' #486

Closed
@kmonarch

Description

问题提交

标题格式:[BUG]: 问题简介

内容需包含:

1、BUG 描述

代码如下

ElevatedButton(
          key: _globalKey,
          onPressed: () {
            BrnPopupWindow.showPopWindow(
                context, "订阅搜索条件,新上房源立即通知", _globalKey,
                hasCloseIcon: true,
                dismissCallback: () {},
                popDirection: BrnPopupDirection.bottom);
          },
          child: Text("右侧带关闭Tips"),
        ),

2、复现步骤
点击之后会报错如下:

======== Exception caught by widgets library =======================================================
The following assertion was thrown building Builder:
dependOnInheritedWidgetOfExactType<_ViewScope>() or dependOnInheritedElement() was called before _BrnPopupWindowState.initState() completed.

When an inherited widget changes, for example if the value of Theme.of() changes, its dependent widgets are rebuilt. If the dependent widget's reference to the inherited widget is in a constructor or an initState() method, then the rebuilt dependent widget will not reflect the changes in the inherited widget.

Typically references to inherited widgets should occur in widget build() methods. Alternatively, initialization based on inherited widgets can be placed in the didChangeDependencies method, which is called after initState and whenever the dependencies change thereafter.

The relevant error-causing widget was: 
  MaterialApp MaterialApp:file:///Users/udel/workspace/Charles_Projects/flutter_demo_collection/common_test_demo/lib/main.dart:34:12
When the exception was thrown, this was the stack: 
#0      StatefulElement.dependOnInheritedElement.<anonymous closure> (package:flutter/src/widgets/framework.dart:5321:9)
#1      StatefulElement.dependOnInheritedElement (package:flutter/src/widgets/framework.dart:5364:6)
#2      LookupBoundary.dependOnInheritedWidgetOfExactType (package:flutter/src/widgets/lookup_boundary.dart:97:13)
#3      View.maybeOf (package:flutter/src/widgets/view.dart:65:27)
#4      View.of (package:flutter/src/widgets/view.dart:85:33)
#5      _BrnPopupWindowState.initState (package:bruno/src/components/popup/brn_popup_window.dart:195:29)
#6      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5219:55)
#7      ComponentElement.mount (package:flutter/src/widgets/framework.dart:5062:5)
...     Normal element mounting (151 frames)
#158    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#159    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#160    Element.updateChild (package:flutter/src/widgets/framework.dart:3708:18)
#161    RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:6153:32)
#162    MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6595:17)
#163    Element.updateChild (package:flutter/src/widgets/framework.dart:3686:15)
#164    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5111:16)
#165    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5251:11)

3、期望行为

4、运行环境

  • Bruno 版本
    (bruno: ^3.4.2)
  • Flutter Doctor 信息

5、附加信息

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.5 22G74 darwin-arm64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.81.0)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!

包括视频、图片等补充信息

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions