Skip to content

Instantly share code, notes, and snippets.

@NishantDesai1306
Created June 29, 2019 09:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NishantDesai1306/7e49987dbf5623ef7dceaecc6cecaaaf to your computer and use it in GitHub Desktop.
Save NishantDesai1306/7e49987dbf5623ef7dceaecc6cecaaaf to your computer and use it in GitHub Desktop.
portion of default_app_bar.dart
// 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