Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart OverlayEntry.remove()不';t从OverlyState中删除条目_Dart_Flutter_Overlay - Fatal编程技术网

Dart OverlayEntry.remove()不';t从OverlyState中删除条目

Dart OverlayEntry.remove()不';t从OverlyState中删除条目,dart,flutter,overlay,Dart,Flutter,Overlay,我正在使用颤振1.2.1编写一个颤振应用程序 在我的StatefulWidget的initState()中,我调用了一个使用以下代码创建的showOverlay()函数: void showOverlay(BuildContext context) async { final OverlayState overlayState = Overlay.of(context); final OverlayEntry overlayEntry = OverlayEntry(

我正在使用颤振1.2.1编写一个颤振应用程序

在我的
StatefulWidget
initState()
中,我调用了一个使用以下代码创建的
showOverlay()
函数:

 void showOverlay(BuildContext context) async {
    final OverlayState overlayState = Overlay.of(context);
    final OverlayEntry overlayEntry = OverlayEntry(
      builder: (BuildContext context)=>Positioned(
        left: 0.0,
        right: 0,
        bottom: 90.0,
        child: Container(
            margin: const EdgeInsets.all(15.0),
            padding: const EdgeInsets.all(3.0),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(25.0),
                border: Border.all(color: Colors.blueAccent)
            ),
          child:
                Text('Focus, lighting and contrast help',style: TextStyle(fontWeight: FontWeight.normal,
                    color: Colors.white,
                    fontSize: 18.0,
                    decoration: TextDecoration.none)),

          )
        ),
    );
    overlayState.insert(overlayEntry);
    await Future<dynamic>.delayed(Duration(seconds: 2));
    overlayEntry.remove();

  }
void showOverlay(BuildContext上下文)异步{
最终overlystate overlystate=Overlay.of(上下文);
最终覆盖入口覆盖入口=覆盖入口(
生成器:(BuildContext上下文)=>已定位(
左:0.0,
右:0,,
底部:90.0,
子:容器(
边距:所有常数边集(15.0),
填充:常数边集全部(3.0),
装饰:盒子装饰(
边界半径:边界半径。圆形(25.0),
边框:border.all(颜色:Colors.blueAccent)
),
儿童:
文本(“聚焦、照明和对比度帮助”,样式:TextStyle(fontWeight:fontWeight.normal,
颜色:颜色,白色,
字体大小:18.0,
装饰:text装饰。无),
)
),
);
覆盖。插入(覆盖入口);
等待未来。延迟(持续时间(秒:2));
覆盖入口。移除();
}
问题是,在2秒延迟后,叠加仍在屏幕上绘制

我错过了什么


谢谢

当我调试时,我注意到以下警告:

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.
我在谷歌上搜索发现了这个问题:

所以为了解决这个问题,我改变了

overlayState.insert(overlayEntry);
为此:

WidgetsBinding.instance.addPostFrameCallback((_) => overlayState.insert(overlayEntry));

@pskink-从过去的会议?!有意思。。我会调查的。谢谢