import 'package:flutter/material.dart';
import 'navigation_observer.dart';

mixin RouteAwareState<T extends StatefulWidget> on State<T> implements RouteAware {
  @override
  void didPopNext() {
    // When returning to this route, subclasses can override to refresh state.
  }

  void subscribeRouteAware() {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final route = ModalRoute.of(context);
      if (route != null) {
        routeObserver.subscribe(this, route);
      }
    });
  }

  void unsubscribeRouteAware() {
    routeObserver.unsubscribe(this);
  }
}

