Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MaterialApp builder error : No Overlay widget found

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.

like image 917
akshay bhange Avatar asked Mar 02 '23 14:03

akshay bhange


1 Answers

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 
    );
  }
}
like image 173
Coala Jedi Avatar answered Mar 05 '23 04:03

Coala Jedi