Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
2bb19a95
Unverified
Commit
2bb19a95
authored
Dec 19, 2023
by
Fedor Blagodyr
Committed by
GitHub
Dec 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added onEnd callback into AnimatedSize (#139859)
close #106439
parent
5a5683dd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
1 deletion
+96
-1
animated_size.dart
packages/flutter/lib/src/rendering/animated_size.dart
+27
-0
animated_size.dart
packages/flutter/lib/src/widgets/animated_size.dart
+14
-1
animated_size_test.dart
packages/flutter/test/widgets/animated_size_test.dart
+55
-0
No files found.
packages/flutter/lib/src/rendering/animated_size.dart
View file @
2bb19a95
...
...
@@ -82,6 +82,7 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
super
.
textDirection
,
super
.
child
,
Clip
clipBehavior
=
Clip
.
hardEdge
,
VoidCallback
?
onEnd
,
})
:
_vsync
=
vsync
,
_clipBehavior
=
clipBehavior
{
_controller
=
AnimationController
(
...
...
@@ -97,6 +98,7 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
parent:
_controller
,
curve:
curve
,
);
_onEnd
=
onEnd
;
}
/// When asserts are enabled, returns the animation controller that is used
...
...
@@ -203,6 +205,19 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
_controller
.
resync
(
vsync
);
}
/// Called every time an animation completes.
///
/// This can be useful to trigger additional actions (e.g. another animation)
/// at the end of the current animation.
VoidCallback
?
get
onEnd
=>
_onEnd
;
VoidCallback
?
_onEnd
;
set
onEnd
(
VoidCallback
?
value
)
{
if
(
value
==
_onEnd
)
{
return
;
}
_onEnd
=
value
;
}
@override
void
attach
(
PipelineOwner
owner
)
{
super
.
attach
(
owner
);
...
...
@@ -216,11 +231,13 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
// already, to resume interrupted resizing animation.
markNeedsLayout
();
}
_controller
.
addStatusListener
(
_animationStatusListener
);
}
@override
void
detach
()
{
_controller
.
stop
();
_controller
.
removeStatusListener
(
_animationStatusListener
);
super
.
detach
();
}
...
...
@@ -363,6 +380,16 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
}
}
void
_animationStatusListener
(
AnimationStatus
status
)
{
switch
(
status
)
{
case
AnimationStatus
.
completed
:
_onEnd
?.
call
();
case
AnimationStatus
.
dismissed
:
case
AnimationStatus
.
forward
:
case
AnimationStatus
.
reverse
:
}
}
@override
void
paint
(
PaintingContext
context
,
Offset
offset
)
{
if
(
child
!=
null
&&
_hasVisualOverflow
&&
clipBehavior
!=
Clip
.
none
)
{
...
...
packages/flutter/lib/src/widgets/animated_size.dart
View file @
2bb19a95
...
...
@@ -31,6 +31,7 @@ class AnimatedSize extends StatefulWidget {
required
this
.
duration
,
this
.
reverseDuration
,
this
.
clipBehavior
=
Clip
.
hardEdge
,
this
.
onEnd
,
});
/// The widget below this widget in the tree.
...
...
@@ -78,6 +79,12 @@ class AnimatedSize extends StatefulWidget {
/// Defaults to [Clip.hardEdge].
final
Clip
clipBehavior
;
/// Called every time an animation completes.
///
/// This can be useful to trigger additional actions (e.g. another animation)
/// at the end of the current animation.
final
VoidCallback
?
onEnd
;
@override
State
<
AnimatedSize
>
createState
()
=>
_AnimatedSizeState
();
}
...
...
@@ -93,6 +100,7 @@ class _AnimatedSizeState
reverseDuration:
widget
.
reverseDuration
,
vsync:
this
,
clipBehavior:
widget
.
clipBehavior
,
onEnd:
widget
.
onEnd
,
child:
widget
.
child
,
);
}
...
...
@@ -107,6 +115,7 @@ class _AnimatedSize extends SingleChildRenderObjectWidget {
this
.
reverseDuration
,
required
this
.
vsync
,
this
.
clipBehavior
=
Clip
.
hardEdge
,
this
.
onEnd
,
});
final
AlignmentGeometry
alignment
;
...
...
@@ -119,6 +128,8 @@ class _AnimatedSize extends SingleChildRenderObjectWidget {
final
Clip
clipBehavior
;
final
VoidCallback
?
onEnd
;
@override
RenderAnimatedSize
createRenderObject
(
BuildContext
context
)
{
return
RenderAnimatedSize
(
...
...
@@ -129,6 +140,7 @@ class _AnimatedSize extends SingleChildRenderObjectWidget {
vsync:
vsync
,
textDirection:
Directionality
.
maybeOf
(
context
),
clipBehavior:
clipBehavior
,
onEnd:
onEnd
,
);
}
...
...
@@ -141,7 +153,8 @@ class _AnimatedSize extends SingleChildRenderObjectWidget {
..
curve
=
curve
..
vsync
=
vsync
..
textDirection
=
Directionality
.
maybeOf
(
context
)
..
clipBehavior
=
clipBehavior
;
..
clipBehavior
=
clipBehavior
..
onEnd
=
onEnd
;
}
@override
...
...
packages/flutter/test/widgets/animated_size_test.dart
View file @
2bb19a95
...
...
@@ -87,6 +87,61 @@ void main() {
expect
(
box
.
size
.
height
,
equals
(
100.0
));
});
testWidgets
(
'calls onEnd when animation is completed'
,
(
WidgetTester
tester
)
async
{
int
callCount
=
0
;
void
handleEnd
()
{
callCount
++;
}
await
tester
.
pumpWidget
(
Center
(
child:
AnimatedSize
(
onEnd:
handleEnd
,
duration:
const
Duration
(
milliseconds:
200
),
child:
const
SizedBox
(
width:
100.0
,
height:
100.0
,
),
),
),
);
expect
(
callCount
,
equals
(
0
));
await
tester
.
pumpWidget
(
Center
(
child:
AnimatedSize
(
onEnd:
handleEnd
,
duration:
const
Duration
(
milliseconds:
200
),
child:
const
SizedBox
(
width:
200.0
,
height:
200.0
,
),
),
),
);
expect
(
callCount
,
equals
(
0
));
await
tester
.
pumpAndSettle
();
expect
(
callCount
,
equals
(
1
));
await
tester
.
pumpWidget
(
Center
(
child:
AnimatedSize
(
onEnd:
handleEnd
,
duration:
const
Duration
(
milliseconds:
200
),
child:
const
SizedBox
(
width:
100.0
,
height:
100.0
,
),
),
),
);
await
tester
.
pumpAndSettle
();
expect
(
callCount
,
equals
(
2
));
});
testWidgets
(
'clamps animated size to constraints'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
Center
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment