horizontal method

Widget horizontal(
  1. double aniValue,
  2. int index,
  3. double page,
  4. Widget child,
)

Implementation

Widget horizontal(double aniValue, int index, double page, Widget child) {
  /// 0 - origin  1 - 0
  final angle = -originAngle * aniValue + originAngle;
  if (page >= index) {
    /// _pageController.page > index 向右滑动 划出下一页 下一页可见
    return LayoutBuilder(builder: (context, constraints) {
      final halfWide = constraints.maxWidth / 2 - fineTuning;
      final offset = -halfWide * aniValue + halfWide;
      return Transform(
        transform: Matrix4.identity()
          ..setEntry(3, 2, 0.001)
          ..translate(offset, .0, .0)
          ..rotateY(-angle),
        alignment: Alignment.center,
        child: child,
      );
    });
  } else {
    /// _pageController.page < index 向下滑动 划出上一页
    return LayoutBuilder(builder: (context, constraints) {
      final halfWide = constraints.maxWidth / 2 - fineTuning;
      final offset = -halfWide * aniValue + halfWide;
      return Transform(
        transform: Matrix4.identity()
          ..setEntry(3, 2, 0.001)
          ..translate(-offset, .0, .0)
          ..rotateY(angle),
        alignment: Alignment.center,
        child: child,
      );
    });
  }
}