【发布时间】:2020-07-20 01:35:14
【问题描述】:
我在构建 navigationDrawer 时遇到错误,其中 tootlip 小部件需要 materialApp 作为祖先。
这是错误的意思:
I/flutter ( 5780): _TooltipState#bc79e(ticker inactive)):
I/flutter ( 5780): No Overlay widget found.
I/flutter ( 5780): Tooltip widgets require an Overlay widget ancestor for correct operation.
I/flutter ( 5780): The most common way to add an Overlay to an application is to include a MaterialApp or Navigator
I/flutter ( 5780): widget in the runApp() call.
I/flutter ( 5780): The specific widget that failed to find an overlay was:
I/flutter ( 5780): Tooltip
I/flutter ( 5780):
I/flutter ( 5780): The relevant error-causing widget was:
I/flutter ( 5780): AppBar
我的 main.dart 代码
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
... //basic info title & theme
builder: (context, child) => LayoutTemplate(child: child),
initialRoute:"/home",
... //Routing stuff like generate route & navigator key
);
}
}
LayoutTemplate 小部件
class LayoutTemplate extends StatelessWidget {
final Widget child;
const LayoutTemplate({Key key, this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("home"))
drawer: NavDrawer()
body: Column(
children: <Widget>[
//NavigationBar(),
Expanded(
child: child,
)
],
),
);
}
}
抱歉添加了太多代码。我不确定是什么导致了这个问题。可能是来自MaterialApp 的builder 导致了它。
感谢您的帮助。
【问题讨论】:
-
总是发布一个我们可以在本地运行的最小可重现代码,我们怎么知道你的
sl、NavigationService、sizingInformation、Routes.clientList等等等等。几乎你的每一行代码使用项目中定义的字段,但您未共享。你在 SO 上快 6 岁了,所以发布一个可以由其他人运行的 MINIMAL REPRODUCIBLE CODE。 -
我已尝试删除不必要的代码。请检查更新的问题
-
谢谢,你还能修改
initialRoute、onGenerateRoute和navigatorKey吗? -
我在使用 TextField 而不是 Tooltip 时遇到了非常相似的问题。你找到解决办法了吗?我想我们正在学习相同的教程!
标签: flutter dart flutter-layout