Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sososdk committed Apr 24, 2024
1 parent 96313e9 commit 7705ec3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
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

0 comments on commit 7705ec3

Please sign in to comment.