import 'package:flutter/cupertino.dart';
import 'package:go_router/go_router.dart';

extension ContextUtils on BuildContext {
  Future<void> popUntil(String route) async {
    while (route != _matchedLocation && canPop()) {
      pop();
      await Future.delayed(Duration(milliseconds: 10));
    }
  }

  String get _matchedLocation => router?.state.matchedLocation ?? "";

  GoRouter? get router {
    return GoRouter.of(this);
  }
}