【问题标题】:No Overlay widget found despite Scaffold and MaterialApp尽管有 Scaffold 和 MaterialApp,但没有找到 Overlay 小部件
【发布时间】:2021-05-09 12:53:49
【问题描述】:

我在我的应用程序中使用Riverpod 作为全局状态管理器;在这种情况下,我使用它来处理应用程序的启动:如果设备上存在配置文件,它将根据用户的角色直接转到一个屏幕,如果没有这样的配置文件,它会将我们发送到登录屏幕。

给定一个持久用户,我遇到了下一个错误:

======== Exception caught by widgets library =======================================================
The following assertion was thrown building Tooltip("Open navigation menu", dirty, state: _TooltipState#4e2ac(ticker inactive)):
No Overlay widget found.

Tooltip widgets require an Overlay widget ancestor for correct operation.

The most common way to add an Overlay to an application is to include a MaterialApp or Navigator widget in the runApp() call.

The specific widget that failed to find an overlay was: Tooltip
  "Open navigation menu"
The relevant error-causing widget was: 
  AppBar file:///home/luisalaguna/Projects/thesis_cancer/lib/core/presentation/widgets/header.dart:17:12
When the exception was thrown, this was the stack: 
#0      Overlay.of.<anonymous closure> (package:flutter/src/widgets/overlay.dart:306:9)
#1      Overlay.of (package:flutter/src/widgets/overlay.dart:309:6)
#2      _TooltipState.build (package:flutter/src/material/tooltip.dart:457:20)
#3      StatefulElement.build (package:flutter/src/widgets/framework.dart:4612:27)
#4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4495:15)

Header 是一个 AppBar 小部件;如果所有的小部件都不会被 ScaffoldMaterialApp 小部件包裹,这个 bug 就不会奇怪了:

主文件上的代码是this:

class CancerApp extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final _appRouter = AppRouter();
    final bool darkTheme = useProvider(darkThemeProvider);
    final launcherState = useProvider(launcherProvider);

    SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);

    return MaterialApp.router(
      title: 'Thesis Cancer',
      theme: darkTheme ? ThemeData.dark() : ThemeData.light(),
      routerDelegate: _appRouter.delegate(),
      routeInformationParser: _appRouter.defaultRouteParser(),
      // home: SplashScreen()
      builder: (context, router) => launcherState.when(
          loading: () => SplashScreen(),
          needsProfile: () => LoginPage(),
          profileLoaded: () => MainScreen()),
    );
  }
}

关于启动器通知,你可以看到here

在重构此工作流程后,我遇到了这个错误,当profileLoaded 状态返回用户时我没有得到它(我遇到了另一个问题)。

可能是什么问题?

【问题讨论】:

    标签: flutter dart navigation riverpod


    【解决方案1】:

    在您的主题上添加applyElevationOverlayColor: true,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-08
      • 2018-03-23
      • 2020-07-20
      • 2021-11-25
      • 1970-01-01
      • 2020-02-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多