Implement new AnimationStatus getters (#148570)
PR #147801 introduced some convenient `AnimationStatus` getters, but I just realized that `AnimationController` now has 2 getters for the same thing: `isAnimating` and `isRunning`. The intent of this pull request is to correct that mistake, and implement the getters in the appropriate places.
This commit is contained in:
@@ -318,10 +318,10 @@ class AnimatedBezierState extends State<AnimatedBezier>
|
||||
..addListener(() {
|
||||
setState(() {});
|
||||
})
|
||||
..addStatusListener((AnimationStatus state) {
|
||||
if (state == AnimationStatus.completed) {
|
||||
..addStatusListener((AnimationStatus status) {
|
||||
if (status.isCompleted) {
|
||||
reverseAnimation();
|
||||
} else if (state == AnimationStatus.dismissed) {
|
||||
} else if (status.isDismissed) {
|
||||
playAnimation();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@ class ColumnOfTextState extends State<ColumnOfText> with SingleTickerProviderSta
|
||||
duration: const Duration(milliseconds: 300),
|
||||
)
|
||||
..addStatusListener((AnimationStatus status) {
|
||||
if (status == AnimationStatus.completed) {
|
||||
if (status.isCompleted) {
|
||||
setState(() {
|
||||
_showText = !_showText;
|
||||
});
|
||||
|
||||
@@ -276,13 +276,8 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
|
||||
});
|
||||
}
|
||||
|
||||
bool get _backdropPanelVisible {
|
||||
final AnimationStatus status = _controller.status;
|
||||
return status == AnimationStatus.completed || status == AnimationStatus.forward;
|
||||
}
|
||||
|
||||
void _toggleBackdropPanelVisibility() {
|
||||
_controller.fling(velocity: _backdropPanelVisible ? -2.0 : 2.0);
|
||||
_controller.fling(velocity: _controller.isForwardOrCompleted ? -2.0 : 2.0);
|
||||
}
|
||||
|
||||
double get _backdropHeight {
|
||||
@@ -294,7 +289,7 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
|
||||
// the user must either tap its heading or the backdrop's menu icon.
|
||||
|
||||
void _handleDragUpdate(DragUpdateDetails details) {
|
||||
if (_controller.isAnimating || _controller.status == AnimationStatus.completed) {
|
||||
if (!_controller.isDismissed) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -302,7 +297,7 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
|
||||
}
|
||||
|
||||
void _handleDragEnd(DragEndDetails details) {
|
||||
if (_controller.isAnimating || _controller.status == AnimationStatus.completed) {
|
||||
if (!_controller.isDismissed) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -231,10 +231,7 @@ class ExpandingBottomSheetState extends State<ExpandingBottomSheet> with TickerP
|
||||
}
|
||||
|
||||
// Returns true if the cart is open or opening and false otherwise.
|
||||
bool get _isOpen {
|
||||
final AnimationStatus status = _controller.status;
|
||||
return status == AnimationStatus.completed || status == AnimationStatus.forward;
|
||||
}
|
||||
bool get _isOpen => _controller.isForwardOrCompleted;
|
||||
|
||||
// Opens the ExpandingBottomSheet if it's closed, otherwise does nothing.
|
||||
void open() {
|
||||
|
||||
@@ -241,7 +241,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
|
||||
}
|
||||
|
||||
void _handleDragEnd(DragEndDetails details) {
|
||||
if (_controller!.isAnimating || _controller!.status == AnimationStatus.completed) {
|
||||
if (!_controller!.isDismissed) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -254,9 +254,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
|
||||
}
|
||||
|
||||
void _toggleFrontLayer() {
|
||||
final AnimationStatus status = _controller!.status;
|
||||
final bool isOpen = status == AnimationStatus.completed || status == AnimationStatus.forward;
|
||||
_controller!.fling(velocity: isOpen ? -2.0 : 2.0);
|
||||
_controller!.fling(velocity: _controller!.isForwardOrCompleted ? -2.0 : 2.0);
|
||||
}
|
||||
|
||||
Widget _buildStack(BuildContext context, BoxConstraints constraints) {
|
||||
@@ -293,7 +291,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
|
||||
AnimationStatus.dismissed,
|
||||
controller: _controller,
|
||||
child: Visibility(
|
||||
visible: _controller!.status != AnimationStatus.completed,
|
||||
visible: !_controller!.isCompleted,
|
||||
maintainState: true,
|
||||
child: widget.backLayer!,
|
||||
),
|
||||
|
||||
@@ -90,7 +90,7 @@ class _FadeScaleTransitionDemoState extends State<FadeScaleTransitionDemo>
|
||||
);
|
||||
},
|
||||
child: Visibility(
|
||||
visible: _controller.status != AnimationStatus.dismissed,
|
||||
visible: !_controller.isDismissed,
|
||||
child: FloatingActionButton(
|
||||
onPressed: () {},
|
||||
child: const Icon(Icons.add),
|
||||
|
||||
@@ -287,10 +287,14 @@ class _FeatureDiscoveryState extends State<FeatureDiscovery>
|
||||
setState(() {});
|
||||
})
|
||||
..addStatusListener((AnimationStatus animationStatus) {
|
||||
if (animationStatus == AnimationStatus.forward) {
|
||||
setState(() => status = FeatureDiscoveryStatus.open);
|
||||
} else if (animationStatus == AnimationStatus.completed) {
|
||||
rippleController.forward(from: 0.0);
|
||||
switch (animationStatus) {
|
||||
case AnimationStatus.forward:
|
||||
setState(() => status = FeatureDiscoveryStatus.open);
|
||||
case AnimationStatus.completed:
|
||||
rippleController.forward(from: 0.0);
|
||||
case AnimationStatus.reverse:
|
||||
case AnimationStatus.dismissed:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -302,10 +306,14 @@ class _FeatureDiscoveryState extends State<FeatureDiscovery>
|
||||
setState(() {});
|
||||
})
|
||||
..addStatusListener((AnimationStatus animationStatus) {
|
||||
if (animationStatus == AnimationStatus.forward) {
|
||||
setState(() => status = FeatureDiscoveryStatus.ripple);
|
||||
} else if (animationStatus == AnimationStatus.completed) {
|
||||
rippleController.forward(from: 0.0);
|
||||
switch (animationStatus) {
|
||||
case AnimationStatus.forward:
|
||||
setState(() => status = FeatureDiscoveryStatus.ripple);
|
||||
case AnimationStatus.completed:
|
||||
rippleController.forward(from: 0.0);
|
||||
case AnimationStatus.reverse:
|
||||
case AnimationStatus.dismissed:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -317,11 +325,15 @@ class _FeatureDiscoveryState extends State<FeatureDiscovery>
|
||||
setState(() {});
|
||||
})
|
||||
..addStatusListener((AnimationStatus animationStatus) {
|
||||
if (animationStatus == AnimationStatus.forward) {
|
||||
setState(() => status = FeatureDiscoveryStatus.tap);
|
||||
} else if (animationStatus == AnimationStatus.completed) {
|
||||
widget.onTap?.call();
|
||||
cleanUponOverlayClose();
|
||||
switch (animationStatus) {
|
||||
case AnimationStatus.forward:
|
||||
setState(() => status = FeatureDiscoveryStatus.tap);
|
||||
case AnimationStatus.completed:
|
||||
widget.onTap?.call();
|
||||
cleanUponOverlayClose();
|
||||
case AnimationStatus.reverse:
|
||||
case AnimationStatus.dismissed:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -333,11 +345,15 @@ class _FeatureDiscoveryState extends State<FeatureDiscovery>
|
||||
setState(() {});
|
||||
})
|
||||
..addStatusListener((AnimationStatus animationStatus) {
|
||||
if (animationStatus == AnimationStatus.forward) {
|
||||
setState(() => status = FeatureDiscoveryStatus.dismiss);
|
||||
} else if (animationStatus == AnimationStatus.completed) {
|
||||
widget.onDismiss?.call();
|
||||
cleanUponOverlayClose();
|
||||
switch (animationStatus) {
|
||||
case AnimationStatus.forward:
|
||||
setState(() => status = FeatureDiscoveryStatus.dismiss);
|
||||
case AnimationStatus.completed:
|
||||
widget.onDismiss?.call();
|
||||
cleanUponOverlayClose();
|
||||
case AnimationStatus.reverse:
|
||||
case AnimationStatus.dismissed:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -91,19 +91,8 @@ class _CategoryListItemState extends State<CategoryListItem>
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool _shouldOpenList() {
|
||||
switch (_controller.status) {
|
||||
case AnimationStatus.completed:
|
||||
case AnimationStatus.forward:
|
||||
case AnimationStatus.reverse:
|
||||
return false;
|
||||
case AnimationStatus.dismissed:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void _handleTap() {
|
||||
if (_shouldOpenList()) {
|
||||
if (_controller.isDismissed) {
|
||||
_controller.forward();
|
||||
if (widget.onTap != null) {
|
||||
widget.onTap!(true);
|
||||
@@ -148,7 +137,7 @@ class _CategoryListItemState extends State<CategoryListItem>
|
||||
return AnimatedBuilder(
|
||||
animation: _controller.view,
|
||||
builder: _buildHeaderWithChildren,
|
||||
child: _shouldOpenList()
|
||||
child: _controller.isDismissed
|
||||
? null
|
||||
: _ExpandedCategoryDemos(
|
||||
category: widget.category,
|
||||
|
||||
@@ -52,7 +52,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
}
|
||||
|
||||
void _closeSettingId(AnimationStatus status) {
|
||||
if (status == AnimationStatus.dismissed) {
|
||||
if (status.isDismissed) {
|
||||
setState(() {
|
||||
_expandedSettingId = null;
|
||||
});
|
||||
|
||||
@@ -112,7 +112,7 @@ class _SplashPageState extends State<SplashPage>
|
||||
return true;
|
||||
},
|
||||
child: SplashPageAnimation(
|
||||
isFinished: _controller.status == AnimationStatus.dismissed,
|
||||
isFinished: _controller.isDismissed,
|
||||
child: LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
final Animation<RelativeRect> animation = _getPanelAnimation(context, constraints);
|
||||
@@ -122,9 +122,7 @@ class _SplashPageState extends State<SplashPage>
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () {
|
||||
_controller.reverse();
|
||||
},
|
||||
onTap: _controller.reverse,
|
||||
onVerticalDragEnd: (DragEndDetails details) {
|
||||
if (details.velocity.pixelsPerSecond.dy < -200) {
|
||||
_controller.reverse();
|
||||
@@ -168,9 +166,7 @@ class _SplashPageState extends State<SplashPage>
|
||||
_SplashBackLayer(
|
||||
isSplashCollapsed: !_isSplashVisible,
|
||||
effect: _effect,
|
||||
onTap: () {
|
||||
_controller.forward();
|
||||
},
|
||||
onTap: _controller.forward,
|
||||
),
|
||||
PositionedTransition(
|
||||
rect: animation,
|
||||
|
||||
@@ -520,11 +520,7 @@ class _MobileNavState extends State<_MobileNav> with TickerProviderStateMixin {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get _bottomDrawerVisible {
|
||||
final AnimationStatus status = _drawerController.status;
|
||||
return status == AnimationStatus.completed ||
|
||||
status == AnimationStatus.forward;
|
||||
}
|
||||
bool get _bottomDrawerVisible => _drawerController.isForwardOrCompleted;
|
||||
|
||||
void _toggleBottomDrawerVisibility() {
|
||||
if (_drawerController.value < 0.4) {
|
||||
@@ -550,8 +546,7 @@ class _MobileNavState extends State<_MobileNav> with TickerProviderStateMixin {
|
||||
}
|
||||
|
||||
void _handleDragEnd(DragEndDetails details) {
|
||||
if (_drawerController.isAnimating ||
|
||||
_drawerController.status == AnimationStatus.completed) {
|
||||
if (!_drawerController.isDismissed) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,8 +71,7 @@ class _ShrineAppState extends State<ShrineApp>
|
||||
// Save state restoration animation values only when the cart page
|
||||
// fully opens or closes.
|
||||
_controller.addStatusListener((AnimationStatus status) {
|
||||
if (status == AnimationStatus.completed ||
|
||||
status == AnimationStatus.dismissed) {
|
||||
if (!status.isAnimating) {
|
||||
_tabIndex.value = _controller.value;
|
||||
}
|
||||
});
|
||||
@@ -83,8 +82,7 @@ class _ShrineAppState extends State<ShrineApp>
|
||||
// Save state restoration animation values only when the menu page
|
||||
// fully opens or closes.
|
||||
_expandingController.addStatusListener((AnimationStatus status) {
|
||||
if (status == AnimationStatus.completed ||
|
||||
status == AnimationStatus.dismissed) {
|
||||
if (!status.isAnimating) {
|
||||
_expandingTabIndex.value = _expandingController.value;
|
||||
}
|
||||
});
|
||||
@@ -118,9 +116,7 @@ class _ShrineAppState extends State<ShrineApp>
|
||||
|
||||
// Closes the bottom sheet if it is open.
|
||||
Future<bool> _onWillPop() async {
|
||||
final AnimationStatus status = _expandingController.status;
|
||||
if (status == AnimationStatus.completed ||
|
||||
status == AnimationStatus.forward) {
|
||||
if (_expandingController.isForwardOrCompleted) {
|
||||
await _expandingController.reverse();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -338,11 +338,7 @@ class ExpandingBottomSheetState extends State<ExpandingBottomSheet> {
|
||||
}
|
||||
|
||||
// Returns true if the cart is open or opening and false otherwise.
|
||||
bool get _isOpen {
|
||||
final AnimationStatus status = _controller.status;
|
||||
return status == AnimationStatus.completed ||
|
||||
status == AnimationStatus.forward;
|
||||
}
|
||||
bool get _isOpen => _controller.isForwardOrCompleted;
|
||||
|
||||
// Opens the ExpandingBottomSheet if it's closed, otherwise does nothing.
|
||||
void open() {
|
||||
|
||||
@@ -11,35 +11,28 @@ class Scrim extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Size deviceSize = MediaQuery.of(context).size;
|
||||
return ExcludeSemantics(
|
||||
child: AnimatedBuilder(
|
||||
animation: controller,
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
final Color color =
|
||||
const Color(0xFFFFF0EA).withOpacity(controller.value * 0.87);
|
||||
final Widget scrimRectangle = ColoredBox(
|
||||
color: Color.fromRGBO(0xFF, 0xF0, 0xEA, controller.value * 0.87),
|
||||
child: SizedBox.fromSize(size: MediaQuery.sizeOf(context)),
|
||||
);
|
||||
|
||||
final Widget scrimRectangle = Container(
|
||||
width: deviceSize.width, height: deviceSize.height, color: color);
|
||||
|
||||
final bool ignorePointer =
|
||||
(controller.status == AnimationStatus.dismissed);
|
||||
final bool tapToRevert = (controller.status == AnimationStatus.completed);
|
||||
|
||||
if (tapToRevert) {
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
controller.reverse();
|
||||
},
|
||||
child: scrimRectangle,
|
||||
),
|
||||
);
|
||||
} else if (ignorePointer) {
|
||||
return IgnorePointer(child: scrimRectangle);
|
||||
} else {
|
||||
return scrimRectangle;
|
||||
switch (controller.status) {
|
||||
case AnimationStatus.completed:
|
||||
return MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
onTap: controller.reverse,
|
||||
child: scrimRectangle,
|
||||
),
|
||||
);
|
||||
case AnimationStatus.dismissed:
|
||||
return IgnorePointer(child: scrimRectangle);
|
||||
case AnimationStatus.forward || AnimationStatus.reverse:
|
||||
return scrimRectangle;
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user