Reputation: 2504
I'm getting error on building navigationDrawer where tootlip widget needs materialApp as ancestor.
here is what error says :
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
my main.dart code
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 Widget
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,
)
],
),
);
}
}
sorry for adding too much code. I'm not sure what causing the issue. maybe the builder
from MaterialApp
is causing it.
thank you for helping.
Upvotes: 19
Views: 21252
Reputation: 2718
Instead, use your LayoutTemplate
widget in each of your routes:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// ... basic info title & theme
initialRoute:"/home",
routes: [
'/home': (context) => LayoutTemplate(child: Text('Home')),
// etc, for other routes
],
);
}
}
The builder parameter is best used for "inserting [heritable widgets] above the Navigator
or - when the WidgetsApp.router
constructor is used - above the Router
but below the other widgets created by the WidgetsApp
widget, or for replacing the Navigator
/Router
entirely."
WidgetsApp.builder
documentation:
For example, from the
BuildContext
passed to [route builder methods], theDirectionality
,Localizations
,DefaultTextStyle
,MediaQuery
, etc, are all available. They can also be overridden in a way that impacts all the routes in the Navigator or Router.
Upvotes: 1
Reputation: 435
If you're using responsive_framework: ^0.1.4 package and you encountered that problem, heres the fix
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter App',
home: MyHomePage(),
builder: (context, child) {
return Overlay(
initialEntries: [
OverlayEntry(
builder: (context) {
return ResponsiveWrapper.builder(
MyHomePage(),
defaultScale: true,
breakpoints: [
ResponsiveBreakpoint.autoScale(1000),
],
);
},
),
],
);
},
);
}
}
Upvotes: 8
Reputation: 594
In your builder, just return an Overlay widget with the LayoutTemplate as OverlayEntry.
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
);
}
}
Upvotes: 33
Reputation: 27
I fixed this by using home instead of the builder parameter
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
... //basic info title & theme
home: LayoutTemplate(child: child),
initialRoute:"/home",
... //Routing stuff like generate route & navigator key
);
}
}
Upvotes: -3