import 'package:flutter/material.dart';

extension NavigationExtensions on BuildContext {
  void navigateWithName(String routeName, {Object? arguments}) {
    Navigator.pushNamed(this, routeName, arguments: arguments);
  }

  Future<void> navigateReplaceWithName(String routeName, {Object? arguments}) async {
    await Navigator.pushReplacementNamed(this, routeName, arguments: arguments);
  }

  void navigateReplaceWithNameUntilRoute(String routeName, {Object? arguments}) {
    Navigator.pushNamedAndRemoveUntil(this, routeName, (route) => false);
  }

  void pop() {
    Navigator.of(this).pop();
  }

  void pushNavigateTo(Widget page) {
    Navigator.push(this, MaterialPageRoute(builder: (context) => page));
  }

  void popUntilNamed(String routeName) {
    Navigator.popUntil(this, ModalRoute.withName(routeName));
  }
}
