Skip to content

Instantly share code, notes, and snippets.

@NishantDesai1306
Created June 29, 2019 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NishantDesai1306/86be27417d43da62b7f1adc0333ad984 to your computer and use it in GitHub Desktop.
Save NishantDesai1306/86be27417d43da62b7f1adc0333ad984 to your computer and use it in GitHub Desktop.
registering animation listener to our animation controller
bool isInSearchMode = false;
// inside initState register our status listener
_controller.addStatusListener(animationStatusListener);
// add this method to our DefaultAppBar widget
animationStatusListener(AnimationStatus animationStatus) {
if (animationStatus == AnimationStatus.completed) {
setState(() {
isInSearchMode = true;
});
}
}
// depending on isInSearchMode decide whether we should render SearchBar()
// or an empty Container() in render method of DefaultAppBar
render() {
return Stack(
children: [
// default app bar
// animated builder which handles ripple animation
AnimatedBuilder(
animation: _animation,
builder: (context, child) {
return CustomPaint(
painter: MyPainter(
containerHeight: widget.preferredSize.height,
center: Offset(rippleStartX ?? 0, rippleStartY ?? 0),
radius: _animation.value * screenWidth,
context: context,
),
);
},
),
// search bar depending on whether app bar is in search mode or not
isInSearchMode ? (
SearchBar()
) : (
Container()
)
]
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment