Line data Source code
1 : import 'package:flutter/material.dart';
2 : import 'package:nav/nav.dart';
3 : import 'package:nav/route/custom_page_route_builder.dart';
4 : import 'package:nav/route/clipper_circle.dart';
5 :
6 : class RippleRouteBuilder<T> extends CustomPageRouteBuilder<T> {
7 : final Widget widget;
8 : final AlignmentGeometry? centerAlignment;
9 : final Offset centerOffset;
10 : final double minRadius;
11 : final double maxRadius;
12 :
13 : /// Reveals the next item pushed to the navigation using circle shape.
14 : ///
15 : /// You can provide [centerAlignment] for the reveal center or if you want a
16 : /// more precise use only [centerOffset] and leave other blank.
17 : ///
18 : /// The transition doesn't affect the entry screen so we will only touch
19 : /// the target screen.
20 1 : RippleRouteBuilder(
21 : this.widget, {
22 : this.minRadius = 0,
23 : required this.maxRadius,
24 : this.centerAlignment,
25 : required this.centerOffset,
26 : int durationMs = Nav.defaultDurationMs,
27 1 : }) : assert(centerAlignment != null),
28 1 : super(
29 1 : transitionDuration: Duration(milliseconds: durationMs),
30 :
31 : /// We could override pageBuilder but it's a required parameter of
32 : /// [PageRouteBuilder] and it won't build unless it's provided.
33 1 : pageBuilder: (
34 : BuildContext context,
35 : Animation<double> animation,
36 : Animation<double> secondaryAnimation,
37 : ) {
38 : return widget;
39 : },
40 : );
41 :
42 1 : @override
43 : Widget buildTransitions(
44 : BuildContext context,
45 : Animation<double> animation,
46 : Animation<double> secondaryAnimation,
47 : Widget child,
48 : ) {
49 1 : return ClipPath(
50 1 : clipper: CircularRevealClipper(
51 1 : fraction: animation.value,
52 1 : centerAlignment: centerAlignment as Alignment?,
53 1 : centerOffset: centerOffset,
54 1 : minRadius: minRadius,
55 1 : maxRadius: maxRadius,
56 : ),
57 : child: child,
58 : );
59 : }
60 : }
|