我在构建 NavigationDrawer 时遇到错误,其中 Tooltip 组件需要以 Material App 为祖先。
以下是错误的具体信息:
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
);
}
}
布局模板小部件
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
引起了问题。
感谢您的帮助。
initialRoute
、onGenerateRoute
和navigatorKey
吗? - iDecode