MaterialApp构建器错误:未找到叠加窗口小部件

问题描述 投票:0回答:1

我在构建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, ) ], ), ); } }
很抱歉,添加了太多代码。我不确定是什么原因引起的。可能是来自builderMaterialApp引起的。

感谢您的帮助。

flutter dart flutter-layout
1个回答
0
投票
有相同的问题。

leading MaterialAppBar属性的文档说明了如何自己实现,我只是删除了tooltip属性,它开始起作用,请参见:https://api.flutter.dev/flutter/material/AppBar/leading.html

AppBar(leading: Builder(builder: (BuildContext context) { return IconButton( icon: const Icon(Icons.menu), onPressed: () { Scaffold.of(context).openDrawer(); } ); }

希望有所帮助。
© www.soinside.com 2019 - 2024. All rights reserved.