|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +import '../_src.g.dart'; |
| 4 | + |
| 5 | +class NoEffect extends AnimationEffect { |
| 6 | + NoEffect() |
| 7 | + : super( |
| 8 | + duration: const Duration(milliseconds: 300), |
| 9 | + curve: Curves.linear, |
| 10 | + data: (context, value) { |
| 11 | + return [const AnimationLayerEffect(), const AnimationLayerEffect()]; |
| 12 | + }, |
| 13 | + ); |
| 14 | +} |
| 15 | + |
| 16 | +class FadeEffect extends AnimationEffect { |
| 17 | + FadeEffect() |
| 18 | + : super( |
| 19 | + duration: const Duration(milliseconds: 375), |
| 20 | + curve: Curves.easeOutSine, |
| 21 | + data: (context, value) { |
| 22 | + return [AnimationLayerEffect(opacity: value), AnimationLayerEffect(opacity: 1.0 - value)]; |
| 23 | + }, |
| 24 | + ); |
| 25 | +} |
| 26 | + |
| 27 | +class QuickLeftToRightEffect extends AnimationEffect { |
| 28 | + QuickLeftToRightEffect() |
| 29 | + : super( |
| 30 | + duration: const Duration(milliseconds: 375), |
| 31 | + curve: Curves.easeInOutQuint, |
| 32 | + data: (context, value) { |
| 33 | + final size = MediaQuery.sizeOf(context); |
| 34 | + final width90 = size.width * 0.9; |
| 35 | + return [ |
| 36 | + AnimationLayerEffect( |
| 37 | + transform: Matrix4.translationValues(-width90 + width90 * value, 0.0, 0.0), |
| 38 | + ), |
| 39 | + AnimationLayerEffect( |
| 40 | + opacity: 1.0 - value * 0.1, |
| 41 | + transform: Matrix4.translationValues(width90 * value * 0.5, 0.0, 0.0), |
| 42 | + ignorePointer: true, |
| 43 | + ), |
| 44 | + ]; |
| 45 | + }, |
| 46 | + ); |
| 47 | +} |
| 48 | + |
| 49 | +class QuickRightToLeftEffect extends AnimationEffect { |
| 50 | + QuickRightToLeftEffect() |
| 51 | + : super( |
| 52 | + duration: const Duration(milliseconds: 375), |
| 53 | + curve: Curves.easeInOutQuint, |
| 54 | + data: (context, value) { |
| 55 | + final size = MediaQuery.sizeOf(context); |
| 56 | + final width90 = size.width * 0.9; |
| 57 | + return [ |
| 58 | + AnimationLayerEffect( |
| 59 | + transform: Matrix4.translationValues(width90 - width90 * value, 0.0, 0.0), |
| 60 | + ), |
| 61 | + AnimationLayerEffect( |
| 62 | + opacity: 1.0 - value * 0.1, |
| 63 | + transform: Matrix4.translationValues(-width90 * value * 0.5, 0.0, 0.0), |
| 64 | + ignorePointer: true, |
| 65 | + ), |
| 66 | + ]; |
| 67 | + }, |
| 68 | + ); |
| 69 | +} |
| 70 | + |
| 71 | +class BottomToTopEffect extends AnimationEffect { |
| 72 | + BottomToTopEffect() |
| 73 | + : super( |
| 74 | + duration: const Duration(milliseconds: 375), |
| 75 | + curve: Curves.easeInOutQuart, |
| 76 | + data: (context, value) { |
| 77 | + final size = MediaQuery.sizeOf(context); |
| 78 | + return [ |
| 79 | + AnimationLayerEffect( |
| 80 | + transform: Matrix4.translationValues(0.0, size.height - size.height * value, 0.0), |
| 81 | + ), |
| 82 | + AnimationLayerEffect( |
| 83 | + opacity: 1.0 - value * 0.1, |
| 84 | + transform: Matrix4.translationValues(0.0, -size.height * value * 0.5, 0.0), |
| 85 | + ignorePointer: true, |
| 86 | + ), |
| 87 | + ]; |
| 88 | + }, |
| 89 | + ); |
| 90 | +} |
| 91 | + |
| 92 | +class TopToBottomEffect extends AnimationEffect { |
| 93 | + TopToBottomEffect() |
| 94 | + : super( |
| 95 | + duration: const Duration(milliseconds: 375), |
| 96 | + curve: Curves.easeInOutQuart, |
| 97 | + data: (context, value) { |
| 98 | + final size = MediaQuery.sizeOf(context); |
| 99 | + return [ |
| 100 | + AnimationLayerEffect( |
| 101 | + transform: Matrix4.translationValues(0.0, -size.height + size.height * value, 0.0), |
| 102 | + ), |
| 103 | + AnimationLayerEffect( |
| 104 | + opacity: 1.0 - value * 0.1, |
| 105 | + transform: Matrix4.translationValues(0.0, size.height * value * 0.5, 0.0), |
| 106 | + ignorePointer: true, |
| 107 | + ), |
| 108 | + ]; |
| 109 | + }, |
| 110 | + ); |
| 111 | +} |
| 112 | + |
| 113 | +class GravityBounceEffect extends AnimationEffect { |
| 114 | + GravityBounceEffect() |
| 115 | + : super( |
| 116 | + duration: const Duration(milliseconds: 900), |
| 117 | + curve: Curves.bounceOut, |
| 118 | + data: (context, value) { |
| 119 | + final size = MediaQuery.sizeOf(context); |
| 120 | + final height75 = size.height * 0.75; |
| 121 | + return [ |
| 122 | + AnimationLayerEffect( |
| 123 | + transform: Matrix4.translationValues(0.0, -height75 + height75 * value, 0.0), |
| 124 | + ), |
| 125 | + const AnimationLayerEffect(ignorePointer: true), |
| 126 | + ]; |
| 127 | + }, |
| 128 | + ); |
| 129 | +} |
| 130 | + |
| 131 | +class CupertinoEffect extends AnimationEffect { |
| 132 | + CupertinoEffect() |
| 133 | + : super( |
| 134 | + duration: const Duration(milliseconds: 410), |
| 135 | + curve: Curves.easeInOut, |
| 136 | + data: (context, value) { |
| 137 | + final size = MediaQuery.sizeOf(context); |
| 138 | + return [ |
| 139 | + AnimationLayerEffect( |
| 140 | + transform: Matrix4.translationValues(size.width - size.width * value, 0.0, 0.0), |
| 141 | + ), |
| 142 | + AnimationLayerEffect( |
| 143 | + opacity: 1.0 - value * 0.1, |
| 144 | + transform: Matrix4.translationValues(-size.width * value * 0.5, 0.0, 0.0), |
| 145 | + ignorePointer: true, |
| 146 | + ), |
| 147 | + ]; |
| 148 | + }, |
| 149 | + ); |
| 150 | +} |
| 151 | + |
| 152 | +class MaterialEffect extends AnimationEffect { |
| 153 | + MaterialEffect() |
| 154 | + : super( |
| 155 | + duration: const Duration(milliseconds: 300), |
| 156 | + curve: Curves.fastOutSlowIn, |
| 157 | + data: (context, value) { |
| 158 | + final size = MediaQuery.sizeOf(context); |
| 159 | + return [ |
| 160 | + AnimationLayerEffect( |
| 161 | + transform: Matrix4.translationValues(size.width - size.width * value, 0.0, 0.0), |
| 162 | + ), |
| 163 | + AnimationLayerEffect( |
| 164 | + opacity: 1.0 - value * 0.1, |
| 165 | + transform: Matrix4.translationValues(-size.width * value * 0.5, 0.0, 0.0), |
| 166 | + ignorePointer: true, |
| 167 | + ), |
| 168 | + ]; |
| 169 | + }, |
| 170 | + ); |
| 171 | +} |
0 commit comments