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
aff731c0
Commit
aff731c0
authored
Oct 25, 2017
by
amirh
Committed by
GitHub
Oct 25, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an AlignTransition widget (#12724)
parent
2b2b3ab5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
0 deletions
+84
-0
transitions.dart
packages/flutter/lib/src/widgets/transitions.dart
+39
-0
transitions_test.dart
packages/flutter/test/widgets/transitions_test.dart
+45
-0
No files found.
packages/flutter/lib/src/widgets/transitions.dart
View file @
aff731c0
...
...
@@ -443,6 +443,45 @@ class DecoratedBoxTransition extends AnimatedWidget {
}
}
/// Animated version of an [Align] that animates its [Align.alignment] property.
class
AlignTransition
extends
AnimatedWidget
{
/// Creates an animated [Align] whose [AlignmentGeometry] animation updates
/// the widget.
///
/// See also:
///
/// * [new Align].
const
AlignTransition
({
Key
key
,
@required
Animation
<
AlignmentGeometry
>
alignment
,
@required
this
.
child
,
this
.
widthFactor
,
this
.
heightFactor
,
})
:
super
(
key:
key
,
listenable:
alignment
);
/// The animation that controls the child's alignment.
Animation
<
AlignmentGeometry
>
get
alignment
=>
listenable
;
/// If non-null, the child's width factor, see [Align.widthFactor].
final
double
widthFactor
;
/// If non-null, the child's height factor, see [Align.heightFactor].
final
double
heightFactor
;
/// The widget below this widget in the tree.
final
Widget
child
;
@override
Widget
build
(
BuildContext
context
)
{
return
new
Align
(
alignment:
alignment
.
value
,
widthFactor:
widthFactor
,
heightFactor:
heightFactor
,
child:
child
,
);
}
}
/// A builder that builds a widget given a child.
///
/// The child should typically be part of the returned widget tree.
...
...
packages/flutter/test/widgets/transitions_test.dart
View file @
aff731c0
...
...
@@ -146,4 +146,49 @@ void main() {
expect
(
actualDecoration
.
boxShadow
[
0
].
color
,
const
Color
(
0x66000000
));
});
});
testWidgets
(
'AlignTransition animates'
,
(
WidgetTester
tester
)
async
{
final
AnimationController
controller
=
new
AnimationController
(
vsync:
const
TestVSync
());
final
Animation
<
Alignment
>
alignmentTween
=
new
AlignmentTween
(
begin:
const
Alignment
(-
1.0
,
0.0
),
end:
const
Alignment
(
1.0
,
1.0
),
).
animate
(
controller
);
final
Widget
widget
=
new
AlignTransition
(
alignment:
alignmentTween
,
child:
const
Text
(
'Ready'
,
textDirection:
TextDirection
.
ltr
),
);
await
tester
.
pumpWidget
(
widget
);
final
RenderPositionedBox
actualPositionedBox
=
tester
.
renderObject
(
find
.
byType
(
Align
));
Alignment
actualAlignment
=
actualPositionedBox
.
alignment
;
expect
(
actualAlignment
,
const
Alignment
(-
1.0
,
0.0
));
controller
.
value
=
0.5
;
await
tester
.
pump
();
actualAlignment
=
actualPositionedBox
.
alignment
;
expect
(
actualAlignment
,
const
Alignment
(
0.0
,
0.5
));
});
testWidgets
(
'AlignTransition keeps width and height factors'
,
(
WidgetTester
tester
)
async
{
final
AnimationController
controller
=
new
AnimationController
(
vsync:
const
TestVSync
());
final
Animation
<
Alignment
>
alignmentTween
=
new
AlignmentTween
(
begin:
const
Alignment
(-
1.0
,
0.0
),
end:
const
Alignment
(
1.0
,
1.0
),
).
animate
(
controller
);
final
Widget
widget
=
new
AlignTransition
(
alignment:
alignmentTween
,
child:
const
Text
(
'Ready'
,
textDirection:
TextDirection
.
ltr
),
widthFactor:
0.3
,
heightFactor:
0.4
,
);
await
tester
.
pumpWidget
(
widget
);
final
Align
actualAlign
=
tester
.
widget
(
find
.
byType
(
Align
));
expect
(
actualAlign
.
widthFactor
,
0.3
);
expect
(
actualAlign
.
heightFactor
,
0.4
);
});
}
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