美文网首页
实现孔雀开屏切页面效果

实现孔雀开屏切页面效果

作者: PharkiLL | 来源:发表于2020-07-14 18:01 被阅读0次
    效果图

    封装动画

    import 'dart:math';
    import './Search.dart';
    class CirclePath extends CustomClipper<Path> {
      CirclePath(this.value);
    
      final double value;
    
      @override
      Path getClip(Size size) {
        var path = Path();
        double radius =
            value * sqrt(size.height * size.height + size.width * size.width);
        path.addOval(Rect.fromLTRB(
            size.width - radius, -radius, size.width + radius, radius));
        return path;
      }
    
      @override
      bool shouldReclip(CustomClipper<Path> oldClipper) {
        return true;
      }
    }
    
    class CirclePageRoute extends PageRoute {
      CirclePageRoute({
        @required this.builder,
        this.transitionDuration = const Duration(milliseconds: 500),
        this.opaque = true,
        this.barrierDismissible = false,
        this.barrierColor,
        this.barrierLabel,
        this.maintainState = true,
      });
    
      final WidgetBuilder builder;
    
      @override
      final Duration transitionDuration;
    
      @override
      final bool opaque;
    
      @override
      final bool barrierDismissible;
    
      @override
      final Color barrierColor;
    
      @override
      final String barrierLabel;
    
      @override
      final bool maintainState;
    
      @override
      Widget buildPage(BuildContext context, Animation<double> animation,
          Animation<double> secondaryAnimation) {
        return AnimatedBuilder(
          animation: animation,
          builder: (context, child) {
            return ClipPath(
              clipper: CirclePath(animation.value),
              child: child,
            );
          },
          child: builder(context),
        );
      }
    }
    

    使用

    Navigator.of(context).push(CirclePageRoute(builder: (context) {
      return SearchPage();
    }));
    

    转自 老孟程序员

    相关文章

      网友评论

          本文标题:实现孔雀开屏切页面效果

          本文链接:https://www.haomeiwen.com/subject/zpvfhktx.html