Created
June 29, 2019 09:47
-
-
Save NishantDesai1306/86be27417d43da62b7f1adc0333ad984 to your computer and use it in GitHub Desktop.
registering animation listener to our animation controller
This file contains 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
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