Skip to content

Commit

Permalink
Make PageInfo.redirect and PageInfo.root const
Browse files Browse the repository at this point in the history
  • Loading branch information
Milad-Akarie committed Jul 31, 2024
1 parent 1c0ae74 commit 6b26102
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions auto_route/lib/src/route/page_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,42 @@ class PageInfo {
return const AutoRouter();
}


@override
bool operator ==(Object other) =>
identical(this, other) ||
other is PageInfo &&
runtimeType == other.runtimeType &&
builder == other.builder &&
name == other.name;
other is PageInfo && runtimeType == other.runtimeType && builder == other.builder && name == other.name;

@override
int get hashCode => name.hashCode ^ builder.hashCode;

/// Dummy [PageInfo] used to represent a redirect route
static final redirect = _NoBuilderPageInfo('#Redirect-Route');
static const redirect = _NoBuilderPageInfo('#Redirect-Route');

/// Dummy [PageInfo] used to represent the root route
static final root = _NoBuilderPageInfo('#Root');
static const root = _NoBuilderPageInfo('#Root');

/// Creates a new instance of [PageInfo] with the given parameters
PageInfo copyWith({
String? name,
AutoRoutePageBuilder? builder,
}) {
return PageInfo(
name ?? this.name,
builder: builder ?? this.builder,
);
}
}

/// Dummy [PageInfo] used to represent a redirect route
class _NoBuilderPageInfo extends PageInfo {
/// Default constructor
_NoBuilderPageInfo(super.name)
const _NoBuilderPageInfo(super.name)
: super(
builder: (data) {
throw FlutterError('RedirectPageInfo does not have a builder');
},
builder: _noBuilder,
);

static Widget _noBuilder(RouteData _) {
throw FlutterError('PageInfo does not have a builder');
}
}

0 comments on commit 6b26102

Please sign in to comment.