OverlayEntry.remove () не удаляет запись из overlayState - PullRequest
0 голосов
/ 22 апреля 2019

Я пишу приложение флаттера, используя Flutter 1.2.1.

внутри initState() моего StatefulWidget Я вызываю 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();

  }

проблема в том, что после 2-секундной задержки на экране по-прежнему отображается оверлей.

что мне не хватает?

спасибо

1 Ответ

0 голосов
/ 23 апреля 2019

при отладке я заметил следующее предупреждение:

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.

Я гуглил и нашел эту проблему: https://github.com/flutter/flutter/issues/21638

, чтобы решить эту проблему, я изменил

overlayState.insert(overlayEntry);

к этому:

WidgetsBinding.instance.addPostFrameCallback((_) => overlayState.insert(overlayEntry));
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...