import 'package:flutter/material.dart';

import 'package:flutter/widgets.dart';

class CustomTransitionRoute<T> extends PageRoute<T> {
  CustomTransitionRoute({
    required this.builder,
    RouteSettings? settings,
    this.begin = const Offset(0.0, 1.0),
    this.end = const Offset(0.0, 0.0),
  }) : super(settings: settings, fullscreenDialog: false);

  final WidgetBuilder builder;
  final Offset begin;
  final Offset end;

  @override
  bool get opaque => false;

  @override
  Color? get barrierColor => null;

  @override
  String? get barrierLabel => null;

  @override
  bool get maintainState => true;

  @override
  Duration get transitionDuration => Duration(milliseconds: 200);

  @override
  Widget buildPage(BuildContext context, Animation<double> animation,
      Animation<double> secondaryAnimation) {
    final result = builder(context);
    return SlideTransition(
      position:
          Tween<Offset>(begin: this.begin, end: this.end).animate(animation),
      child: Semantics(
        scopesRoute: true,
        explicitChildNodes: true,
        child: result,
      ),
    );
  }
}
