Skip to content
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 flutter_modular/lib/src/presenter/models/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,16 @@ class CustomTransition {
Animation<double>,
Animation<double>,
)? pageBuilder;
final RouteBuilder? routeBuilder;
final Duration transitionDuration;
final Duration reverseTransitionDuration;
final bool opaque;

CustomTransition(
{required this.transitionBuilder,
this.pageBuilder,
this.routeBuilder,
this.transitionDuration = const Duration(milliseconds: 300),
this.reverseTransitionDuration = const Duration(milliseconds: 300),
this.opaque = true,
this.pageBuilder});
this.opaque = true});
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class ModularPage<T> extends Page<T> {
if (transitionType == TransitionType.custom &&
route.customTransition != null) {
final transition = route.customTransition!;
if (transition.routeBuilder != null) {
return transition.routeBuilder!((context) => page, this) as Route<T>;
}

return PageRouteBuilder<T>(
pageBuilder: transition.pageBuilder ?? (context, _, __) => page,
opaque: transition.opaque,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,25 @@ void main() {
expect(page.createRoute(context), isA<Route>());
expect(page.route.isFullscreenDialog, equals(true));
});

test('createRoute custom route builder', () {
final args = ModularArguments.empty();
final context = BuildContextMock();
final route = ParallelRouteMock();
final widget = Container();
when(() => route.child).thenReturn((_) => widget);
when(() => route.uri).thenReturn(Uri.parse('/'));
when(() => route.transition).thenReturn(TransitionType.custom);
when(() => route.customTransition).thenReturn(CustomTransition(
transitionBuilder: (_, __, ___, child) => child,
routeBuilder: (builder, settings) => CupertinoSheetRoute(
builder: builder,
settings: settings,
),
));

final page = ModularPage(args: args, flags: ModularFlags(), route: route);
final pageRoute = page.createRoute(context);
expect(pageRoute, isA<CupertinoSheetRoute>());
});
}