Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #1913 #1942

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions auto_route/lib/src/route/auto_route_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class AdaptiveRoute extends AutoRoute {

/// Builds an [AutoRoute] instance with [RouteType.custom] type
@immutable
class CustomRoute extends AutoRoute {
class CustomRoute<T> extends AutoRoute {
/// Default constructor
CustomRoute({
required PageInfo page,
Expand All @@ -368,7 +368,7 @@ class CustomRoute extends AutoRoute {
super.initial,
super.allowSnapshotting = true,
RouteTransitionsBuilder? transitionsBuilder,
CustomRouteBuilder? customRouteBuilder,
CustomRouteBuilder<T>? customRouteBuilder,
int? durationInMilliseconds,
int? reverseDurationInMilliseconds,
bool opaque = true,
Expand All @@ -378,7 +378,7 @@ class CustomRoute extends AutoRoute {
Color? barrierColor,
}) : super._(
name: page.name,
type: RouteType.custom(
type: RouteType<T>.custom(
transitionsBuilder: transitionsBuilder,
customRouteBuilder: customRouteBuilder,
durationInMilliseconds: durationInMilliseconds,
Expand Down
14 changes: 7 additions & 7 deletions auto_route/lib/src/route/route_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef CustomRouteBuilder<T> = Route<T> Function(

/// An abstraction of route types used by
/// [AutoRoutePage.onCreateRoute] to decide transition animations
abstract class RouteType {
abstract class RouteType<T> {
const RouteType._({this.opaque = true});

/// Whether the target [Route] should be opaque
Expand Down Expand Up @@ -40,7 +40,7 @@ abstract class RouteType {
/// Builds a [CustomRouteType] route type
const factory RouteType.custom({
RouteTransitionsBuilder? transitionsBuilder,
CustomRouteBuilder? customRouteBuilder,
CustomRouteBuilder<T>? customRouteBuilder,
int? durationInMilliseconds,
int? reverseDurationInMilliseconds,
bool opaque,
Expand All @@ -51,13 +51,13 @@ abstract class RouteType {
}

/// Generates a route that uses [MaterialRouteTransitionMixin]
class MaterialRouteType extends RouteType {
class MaterialRouteType<T> extends RouteType<T> {
/// Default constructor
const MaterialRouteType() : super._(opaque: true);
}

/// Generates a route that uses [CupertinoRouteTransitionMixin]
class CupertinoRouteType extends RouteType {
class CupertinoRouteType<T> extends RouteType<T> {
/// Default constructor
const CupertinoRouteType() : super._(opaque: true);
}
Expand All @@ -67,13 +67,13 @@ class CupertinoRouteType extends RouteType {
/// ios,macos => [CupertinoRouteTransitionMixin]
/// web => NoTransition
/// any other platform => [MaterialRouteTransitionMixin]
class AdaptiveRouteType extends RouteType {
class AdaptiveRouteType<T> extends RouteType<T> {
/// Default constructor
const AdaptiveRouteType({super.opaque}) : super._();
}

/// Generates a route with user-defined transitions
class CustomRouteType extends RouteType {
class CustomRouteType<T> extends RouteType<T> {
/// this builder function is passed to the transition builder
/// function in [PageRouteBuilder]
///
Expand All @@ -98,7 +98,7 @@ class CustomRouteType extends RouteType {
/// this builder function accepts a BuildContext and a CustomPage
/// that has all the other properties assigned to it
/// so using them then is totally up to you.
final CustomRouteBuilder? customRouteBuilder;
final CustomRouteBuilder<T>? customRouteBuilder;

/// route transition duration in milliseconds
/// is passed to [PageRouteBuilder]
Expand Down
5 changes: 3 additions & 2 deletions auto_route/lib/src/router/auto_route_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ class AutoRoutePage<T> extends Page<T> {
return _PageBasedCupertinoPageRoute<T>(page: this, title: title);
} else if (type is CustomRouteType) {
final result = buildPage(context);
if (type.customRouteBuilder != null) {
return type.customRouteBuilder!(context, result, this) as Route<T>;
final builder = (type as CustomRouteType<T>).customRouteBuilder;
if (builder != null) {
return builder(context, result, this);
}
return _CustomPageBasedPageRouteBuilder<T>(page: this, routeType: type);
} else if (type is AdaptiveRouteType) {
Expand Down