Is a Flutter widget on top of Navigator

One thing that I keep forgetting how to do in Flutter is determine if a Widget is the topmost visible widget or has been obscured by the Navigator pushing another widget on top of it. It’s really simple so I’m recording it here so I don’t have to search for it again.

class MyWidget extends StatelessWidget {

  bool isOnTop( BuildContext context ) {
    return ModalRoute.of(context).isCurrent
  }
}

Leave a Reply