respect disableAnimations flag
This commit is contained in:
@@ -120,12 +120,24 @@ class _AnimateGradientShaderState extends State<AnimateGradientShader>
|
||||
List<Color> primaryColors = [];
|
||||
List<Color> secondaryColors = [];
|
||||
|
||||
bool _disableAnimations = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_initialize();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final disableAnimations = MediaQuery.disableAnimationsOf(context);
|
||||
if (disableAnimations != _disableAnimations) {
|
||||
_disableAnimations = disableAnimations;
|
||||
_setAnimations();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(AnimateGradientShader oldWidget) {
|
||||
_initialize();
|
||||
@@ -222,10 +234,15 @@ class _AnimateGradientShaderState extends State<AnimateGradientShader>
|
||||
void _setAnimations() {
|
||||
_controller?.dispose();
|
||||
_controller =
|
||||
(widget.controller ??
|
||||
AnimationController(vsync: this, duration: widget.duration))
|
||||
// ignore: discarded_futures
|
||||
..repeat(reverse: widget.reverse);
|
||||
widget.controller ??
|
||||
AnimationController(vsync: this, duration: widget.duration);
|
||||
|
||||
if (_disableAnimations) {
|
||||
_controller!.value = 0;
|
||||
} else {
|
||||
// ignore: discarded_futures
|
||||
_controller!.repeat(reverse: widget.reverse);
|
||||
}
|
||||
|
||||
_animation = CurvedAnimation(parent: _controller!, curve: Curves.easeInOut);
|
||||
}
|
||||
|
||||
@@ -129,12 +129,30 @@ class _AnimatedIndexedStackState extends State<AnimatedIndexedStack>
|
||||
/// The entry which is currently at the top of the stack.
|
||||
_ChildEntry? _currentEntry;
|
||||
|
||||
bool _disableAnimations = false;
|
||||
|
||||
Duration get _effectiveDuration =>
|
||||
_disableAnimations ? Duration.zero : widget.duration;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_updateEntriesList();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final disableAnimations = MediaQuery.disableAnimationsOf(context);
|
||||
if (disableAnimations != _disableAnimations) {
|
||||
_disableAnimations = disableAnimations;
|
||||
for (final entry in _entries) {
|
||||
entry.primaryController.duration = _effectiveDuration;
|
||||
entry.secondaryController.duration = _effectiveDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(AnimatedIndexedStack oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
@@ -207,8 +225,8 @@ class _AnimatedIndexedStackState extends State<AnimatedIndexedStack>
|
||||
// If we find an existing entry, we update its child widget and reuse it.
|
||||
// This ensures it continues to use the same global key and animation controllers.
|
||||
existingEntry.child = child;
|
||||
existingEntry.primaryController.duration = widget.duration;
|
||||
existingEntry.secondaryController.duration = widget.duration;
|
||||
existingEntry.primaryController.duration = _effectiveDuration;
|
||||
existingEntry.secondaryController.duration = _effectiveDuration;
|
||||
entry = existingEntry;
|
||||
} else {
|
||||
entry = _newEntry(child);
|
||||
@@ -299,11 +317,11 @@ class _AnimatedIndexedStackState extends State<AnimatedIndexedStack>
|
||||
key: GlobalKey(),
|
||||
child: child,
|
||||
primaryController: AnimationController(
|
||||
duration: widget.duration,
|
||||
duration: _effectiveDuration,
|
||||
vsync: this,
|
||||
),
|
||||
secondaryController: AnimationController(
|
||||
duration: widget.duration,
|
||||
duration: _effectiveDuration,
|
||||
vsync: this,
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user