gpt4 book ai didi

flutter - MaterialApp 构建器错误 : No Overlay widget found

转载 作者:行者123 更新时间:2023-12-03 03:56:17 32 4
gpt4 key购买 nike

我在构建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
);
}
}

布局模板小部件
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,
)
],
),
);
}
}

抱歉添加了太多代码。我不确定是什么导致了这个问题。也许是 builder来自 MaterialApp导致它。

感谢您的帮助。

最佳答案

在您的构建器中,只需返回一个带有 LayoutTemplate 作为 OverlayEntry 的 Overlay 小部件。

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
... //basic info title & theme

builder: (context, child) {
return Overlay(
initialEntries: [
OverlayEntry(
builder: (context) => LayoutTemplate(child: child),
),
],
);
},
initialRoute:"/home",

... //Routing stuff like generate route & navigator key
);
}
}

关于flutter - MaterialApp 构建器错误 : No Overlay widget found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61087158/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com