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

Expose activeIndex for AutoTabsRouter and RoutingController #2134

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: 4 additions & 2 deletions auto_route/lib/src/router/controller/routing_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,12 @@ class TabsRouter extends RoutingController {
required RouteData routeData,
this.homeIndex = -1,
required this.preload,
RoutingController? parent})
RoutingController? parent,
int activeIndex = 0})
: matcher = RouteMatcher(routeCollection),
_parent = parent,
_routeData = routeData;
_routeData = routeData,
_activeIndex = activeIndex;

/// Called to preload a page before other navigation events occur
/// if it returns true, the page has been preloaded, otherwise we assume it's already loaded
Expand Down
13 changes: 13 additions & 0 deletions auto_route/lib/src/router/widgets/auto_tabs_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ abstract class AutoTabsRouter extends StatefulWidget {
/// else pop parent
final int homeIndex;

/// The index of the `route` to show on first build
final int startIndex;

const AutoTabsRouter._({
super.key,
required this.routes,
this.startIndex = 0,
this.homeIndex = -1,
this.inheritNavigatorObservers = true,
this.navigatorObservers =
Expand All @@ -89,6 +93,7 @@ abstract class AutoTabsRouter extends StatefulWidget {
int homeIndex,
bool inheritNavigatorObservers,
NavigatorObserversBuilder navigatorObservers,
int startIndex,
}) = _AutoTabsRouterIndexedStack;

/// Builds an [AutoTabsRouter] to uses
Expand All @@ -106,6 +111,7 @@ abstract class AutoTabsRouter extends StatefulWidget {
NavigatorObserversBuilder navigatorObservers,
ScrollPhysics? physics,
DragStartBehavior dragStartBehavior,
int startIndex,
}) = _AutoTabsRouterPageView;

/// Builds an [AutoTabsRouter] to uses
Expand All @@ -123,6 +129,7 @@ abstract class AutoTabsRouter extends StatefulWidget {
NavigatorObserversBuilder navigatorObservers,
ScrollPhysics? physics,
DragStartBehavior dragStartBehavior,
int startIndex,
}) = _AutoTabsRouterTabBar;

/// Builds an [AutoTabsRouter] with a custom builder
Expand All @@ -137,6 +144,7 @@ abstract class AutoTabsRouter extends StatefulWidget {
int homeIndex,
bool inheritNavigatorObservers,
NavigatorObserversBuilder navigatorObservers,
int startIndex,
}) = _AutoTabsRouterBuilder;

/// Looks up and returns the scoped [controller]
Expand Down Expand Up @@ -195,6 +203,7 @@ abstract class AutoTabsRouterState<T extends AutoTabsRouter> extends State<T> {
routeCollection: _parentController.routeCollection.subCollectionOf(
parentRoute.name,
),
activeIndex: widget.startIndex,
);
_parentController.attachChildController(_controller!);
_setupController();
Expand Down Expand Up @@ -241,6 +250,7 @@ class _AutoTabsRouterIndexedStack extends AutoTabsRouter {
this.builder,
this.transitionBuilder = _defaultTransitionBuilder,
super.homeIndex,
super.startIndex,
super.inheritNavigatorObservers,
super.navigatorObservers,
}) : super._();
Expand Down Expand Up @@ -487,6 +497,7 @@ class _AutoTabsRouterPageView extends AutoTabsRouter {
super.routes,
AutoTabsPageViewBuilder? builder,
super.homeIndex,
super.startIndex,
this.scrollDirection = Axis.horizontal,
this.animatePageTransition = true,
this.duration = kTabScrollDuration,
Expand Down Expand Up @@ -617,6 +628,7 @@ class _AutoTabsRouterTabBar extends AutoTabsRouter {
this.scrollDirection = Axis.horizontal,
this.builder,
super.homeIndex,
super.startIndex,
this.animatePageTransition = true,
this.duration,
this.curve = Curves.ease,
Expand Down Expand Up @@ -758,6 +770,7 @@ class _AutoTabsRouterBuilder extends AutoTabsRouter {
super.homeIndex,
super.inheritNavigatorObservers,
super.navigatorObservers,
super.startIndex,
}) : super._();

@override
Expand Down