Skip to content

Commit

Permalink
Fixed dropdown menu hide mask no animation
Browse files Browse the repository at this point in the history
  • Loading branch information
GanZhiXiong committed Jun 2, 2020
1 parent 87ff7c3 commit 301ccc8
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions lib/src/gzx_dropdown_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class _GZXDropDownMenuState extends State<GZXDropDownMenu> with SingleTickerProv

double _maskColorOpacity;

double _dropDownHeight;

@override
void initState() {
// TODO: implement initState
Expand All @@ -59,7 +61,10 @@ class _GZXDropDownMenuState extends State<GZXDropDownMenu> with SingleTickerProv
}

dispose() {
_controller.dispose();
_animation?.removeListener(_animationListener);
_animation?.removeStatusListener(_animationStatusListener);
widget.controller?.removeListener(_onController);
_controller?.dispose();
_isControllerDisposed = true;
super.dispose();
}
Expand All @@ -71,18 +76,17 @@ class _GZXDropDownMenuState extends State<GZXDropDownMenu> with SingleTickerProv
}

_isShowDropDownItemWidget = !_isShowDropDownItemWidget;
_isShowMask = !_isShowMask;

var dropDownHeight2 = widget.menus[menuIndex].dropDownHeight;
_animation = new Tween(begin: 0.0, end: dropDownHeight2).animate(_controller)
..addListener(() {
// print('${_animation.value}');
var heightScale = _animation.value / dropDownHeight2;
_maskColorOpacity = widget.maskColor.opacity * heightScale;
// print('$_maskColorOpacity');
//这行如果不写,没有动画效果
setState(() {});
});
if (!_isShowMask) {
_isShowMask = true;
}

_dropDownHeight = widget.menus[menuIndex].dropDownHeight;

_animation?.removeListener(_animationListener);
_animation?.removeStatusListener(_animationStatusListener);
_animation = new Tween(begin: 0.0, end: _dropDownHeight).animate(_controller)
..addListener(_animationListener)
..addStatusListener(_animationStatusListener);

if (_isControllerDisposed) return;

Expand All @@ -97,6 +101,32 @@ class _GZXDropDownMenuState extends State<GZXDropDownMenu> with SingleTickerProv
}
}

void _animationStatusListener(AnimationStatus status) {
switch (status) {
case AnimationStatus.dismissed:
// print('dismissed');
_isShowMask = false;
break;
case AnimationStatus.forward:
// TODO: Handle this case.
break;
case AnimationStatus.reverse:
// TODO: Handle this case.
break;
case AnimationStatus.completed:
// print('completed');
break;
}
}

void _animationListener() {
var heightScale = _animation.value / _dropDownHeight;
_maskColorOpacity = widget.maskColor.opacity * heightScale;
// print('$_maskColorOpacity');
//这行如果不写,没有动画效果
setState(() {});
}

Widget _mask() {
if (_isShowMask) {
return GestureDetector(
Expand Down

0 comments on commit 301ccc8

Please sign in to comment.