Flutter listen to overlay entry insertion

Viewed 56

How can I listen to an overlay that is inserted in flutter?

I have a main screen which consists of a scroll view and a button which opens an overlay.

When the overlay is opened I want to disable scroll on the below scroll view.

Ive tried using RouteAware but it is only executed when pushing another PageRoute.

The listeners are only executed when I push a new route using the main navigator but ive found no solution on how to listen when an overlay is pushed ontop of the current route.

Code:


class MyWidget extends StatelessWidget {

  @override
  _MyWidget State createState() => _MyWidget State();
  
}

class _MyWidgetState extends StatefulWidget<MyWidget> with RouteAware {

  bool _scrollDisabled = false;

  @override
  didChangeDependencies() {
    super.didChangeDependencies();
    
    getIt<RouteObserver>().subscribe(this, ModalRoute.of(context) as PageRoute);
  }

  @override
  dispose() {
    getIt<RouteObserver>().unsubscribe(this);
    super.dispose();
  }

  
  didPushNext() {
    print("didPushNext");

    setState(() {
      _scrollDisabled = true;
    });
  }

  didPush() {
    print("didPush");
  }

}


0 Answers
Related