Created
June 29, 2019 09:34
-
-
Save NishantDesai1306/7e49987dbf5623ef7dceaecc6cecaaaf to your computer and use it in GitHub Desktop.
portion of default_app_bar.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add SingleTickerProviderStateMixin to our State widget | |
class _DefaultAppBarState extends State<DefaultAppBar> with SingleTickerProviderStateMixin { | |
} | |
// intialize animation and controller | |
AnimationController _controller; | |
Animation _animation; | |
@override | |
initState() { | |
super.initState(); | |
_controller = AnimationController(vsync: this, duration: Duration(milliseconds: 800)); | |
_animation = Tween(begin: 0.0, end: 1.0).animate(_controller); | |
} | |
//we'll run the animation in forward direction when user taps on search icon | |
void onSearchTapUp(TapUpDetails details) { | |
setState(() { | |
rippleStartX = details.globalPosition.dx; | |
rippleStartY = details.globalPosition.dy; | |
}); | |
print("pointer location $rippleStartX, $rippleStartY"); | |
// run animation controller in forward direction | |
// as we now have center point for ripple animation | |
_controller.forward(); | |
} | |
// lastly we'll add AnimationBuilder which uses our MyPainter and AnimationController to render ripple animation | |
AnimatedBuilder( | |
animation: _animation, | |
builder: (context, child) { | |
return CustomPaint( | |
painter: MyPainter( | |
containerHeight: widget.preferredSize.height, | |
center: Offset(rippleStartX ?? 0, rippleStartY ?? 0), | |
// increase radius in % from 0% to 100% of screenWidth | |
radius: _animation.value * screenWidth, | |
context: context, | |
), | |
); | |
}, | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment