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
e24cdab5
Unverified
Commit
e24cdab5
authored
Jul 15, 2020
by
Neevash Ramdial
Committed by
GitHub
Jul 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-land Expose height and width factor in AnimatedAlign (#61136)
parent
54f99d64
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
173 additions
and
0 deletions
+173
-0
implicit_animations.dart
packages/flutter/lib/src/widgets/implicit_animations.dart
+26
-0
align_test.dart
packages/flutter/test/widgets/align_test.dart
+47
-0
animated_align_test.dart
packages/flutter/test/widgets/animated_align_test.dart
+100
-0
No files found.
packages/flutter/lib/src/widgets/implicit_animations.dart
View file @
e24cdab5
...
@@ -882,10 +882,14 @@ class AnimatedAlign extends ImplicitlyAnimatedWidget {
...
@@ -882,10 +882,14 @@ class AnimatedAlign extends ImplicitlyAnimatedWidget {
Key
key
,
Key
key
,
@required
this
.
alignment
,
@required
this
.
alignment
,
this
.
child
,
this
.
child
,
this
.
heightFactor
,
this
.
widthFactor
,
Curve
curve
=
Curves
.
linear
,
Curve
curve
=
Curves
.
linear
,
@required
Duration
duration
,
@required
Duration
duration
,
VoidCallback
onEnd
,
VoidCallback
onEnd
,
})
:
assert
(
alignment
!=
null
),
})
:
assert
(
alignment
!=
null
),
assert
(
widthFactor
==
null
||
widthFactor
>=
0.0
),
assert
(
heightFactor
==
null
||
heightFactor
>=
0.0
),
super
(
key:
key
,
curve:
curve
,
duration:
duration
,
onEnd:
onEnd
);
super
(
key:
key
,
curve:
curve
,
duration:
duration
,
onEnd:
onEnd
);
/// How to align the child.
/// How to align the child.
...
@@ -911,6 +915,16 @@ class AnimatedAlign extends ImplicitlyAnimatedWidget {
...
@@ -911,6 +915,16 @@ class AnimatedAlign extends ImplicitlyAnimatedWidget {
/// {@macro flutter.widgets.child}
/// {@macro flutter.widgets.child}
final
Widget
child
;
final
Widget
child
;
/// If non-null, sets its height to the child's height multiplied by this factor.
///
/// Must be greater than or equal to 0.0, defaults to null.
final
double
heightFactor
;
/// If non-null, sets its width to the child's width multiplied by this factor.
///
/// Must be greater than or equal to 0.0, defaults to null.
final
double
widthFactor
;
@override
@override
_AnimatedAlignState
createState
()
=>
_AnimatedAlignState
();
_AnimatedAlignState
createState
()
=>
_AnimatedAlignState
();
...
@@ -923,16 +937,26 @@ class AnimatedAlign extends ImplicitlyAnimatedWidget {
...
@@ -923,16 +937,26 @@ class AnimatedAlign extends ImplicitlyAnimatedWidget {
class
_AnimatedAlignState
extends
AnimatedWidgetBaseState
<
AnimatedAlign
>
{
class
_AnimatedAlignState
extends
AnimatedWidgetBaseState
<
AnimatedAlign
>
{
AlignmentGeometryTween
_alignment
;
AlignmentGeometryTween
_alignment
;
Tween
<
double
>
_heightFactorTween
;
Tween
<
double
>
_widthFactorTween
;
@override
@override
void
forEachTween
(
TweenVisitor
<
dynamic
>
visitor
)
{
void
forEachTween
(
TweenVisitor
<
dynamic
>
visitor
)
{
_alignment
=
visitor
(
_alignment
,
widget
.
alignment
,
(
dynamic
value
)
=>
AlignmentGeometryTween
(
begin:
value
as
AlignmentGeometry
))
as
AlignmentGeometryTween
;
_alignment
=
visitor
(
_alignment
,
widget
.
alignment
,
(
dynamic
value
)
=>
AlignmentGeometryTween
(
begin:
value
as
AlignmentGeometry
))
as
AlignmentGeometryTween
;
if
(
widget
.
heightFactor
!=
null
)
{
_heightFactorTween
=
visitor
(
_heightFactorTween
,
widget
.
heightFactor
,
(
dynamic
value
)
=>
Tween
<
double
>(
begin:
value
as
double
))
as
Tween
<
double
>;
}
if
(
widget
.
widthFactor
!=
null
)
{
_widthFactorTween
=
visitor
(
_widthFactorTween
,
widget
.
widthFactor
,
(
dynamic
value
)
=>
Tween
<
double
>(
begin:
value
as
double
))
as
Tween
<
double
>;
}
}
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Align
(
return
Align
(
alignment:
_alignment
.
evaluate
(
animation
),
alignment:
_alignment
.
evaluate
(
animation
),
heightFactor:
_heightFactorTween
?.
evaluate
(
animation
),
widthFactor:
_widthFactorTween
?.
evaluate
(
animation
),
child:
widget
.
child
,
child:
widget
.
child
,
);
);
}
}
...
@@ -941,6 +965,8 @@ class _AnimatedAlignState extends AnimatedWidgetBaseState<AnimatedAlign> {
...
@@ -941,6 +965,8 @@ class _AnimatedAlignState extends AnimatedWidgetBaseState<AnimatedAlign> {
void
debugFillProperties
(
DiagnosticPropertiesBuilder
description
)
{
void
debugFillProperties
(
DiagnosticPropertiesBuilder
description
)
{
super
.
debugFillProperties
(
description
);
super
.
debugFillProperties
(
description
);
description
.
add
(
DiagnosticsProperty
<
AlignmentGeometryTween
>(
'alignment'
,
_alignment
,
defaultValue:
null
));
description
.
add
(
DiagnosticsProperty
<
AlignmentGeometryTween
>(
'alignment'
,
_alignment
,
defaultValue:
null
));
description
.
add
(
DiagnosticsProperty
<
Tween
<
double
>>(
'widthFactor'
,
_widthFactorTween
,
defaultValue:
null
));
description
.
add
(
DiagnosticsProperty
<
Tween
<
double
>>(
'heightFactor'
,
_heightFactorTween
,
defaultValue:
null
));
}
}
}
}
...
...
packages/flutter/test/widgets/align_test.dart
View file @
e24cdab5
...
@@ -112,4 +112,51 @@ void main() {
...
@@ -112,4 +112,51 @@ void main() {
expect
(
size
.
width
,
equals
(
800.0
));
expect
(
size
.
width
,
equals
(
800.0
));
expect
(
size
.
height
,
equals
(
10.0
));
expect
(
size
.
height
,
equals
(
10.0
));
});
});
testWidgets
(
'Align widthFactor'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Row
(
crossAxisAlignment:
CrossAxisAlignment
.
start
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
Align
(
widthFactor:
0.5
,
child:
Container
(
height:
100.0
,
width:
100.0
,
),
),
],
),
),
);
final
RenderBox
box
=
tester
.
renderObject
<
RenderBox
>(
find
.
byType
(
Align
));
expect
(
box
.
size
.
width
,
equals
(
50.0
));
});
testWidgets
(
'Align heightFactor'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
crossAxisAlignment:
CrossAxisAlignment
.
start
,
children:
<
Widget
>[
Align
(
alignment:
Alignment
.
center
,
heightFactor:
0.5
,
child:
Container
(
height:
100.0
,
width:
100.0
,
),
),
],
),
),
);
final
RenderBox
box
=
tester
.
renderObject
<
RenderBox
>(
find
.
byType
(
Align
));
expect
(
box
.
size
.
height
,
equals
(
50.0
));
});
}
}
packages/flutter/test/widgets/animated_align_test.dart
View file @
e24cdab5
...
@@ -59,4 +59,104 @@ void main() {
...
@@ -59,4 +59,104 @@ void main() {
expect
(
tester
.
getSize
(
find
.
byKey
(
target
)),
const
Size
(
100.0
,
200.0
));
expect
(
tester
.
getSize
(
find
.
byKey
(
target
)),
const
Size
(
100.0
,
200.0
));
expect
(
tester
.
getTopRight
(
find
.
byKey
(
target
)),
const
Offset
(
800.0
,
400.0
));
expect
(
tester
.
getTopRight
(
find
.
byKey
(
target
)),
const
Offset
(
800.0
,
400.0
));
});
});
testWidgets
(
'AnimatedAlign widthFactor'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Row
(
mainAxisSize:
MainAxisSize
.
min
,
children:
<
Widget
>[
AnimatedAlign
(
alignment:
Alignment
.
center
,
curve:
Curves
.
ease
,
widthFactor:
0.5
,
duration:
const
Duration
(
milliseconds:
200
),
child:
Container
(
height:
100.0
,
width:
100.0
,
),
),
],
),
),
);
final
RenderBox
box
=
tester
.
renderObject
<
RenderBox
>(
find
.
byType
(
AnimatedAlign
));
expect
(
box
.
size
.
width
,
equals
(
50.0
));
});
testWidgets
(
'AnimatedAlign heightFactor'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Column
(
children:
<
Widget
>[
AnimatedAlign
(
alignment:
Alignment
.
center
,
curve:
Curves
.
ease
,
heightFactor:
0.5
,
duration:
const
Duration
(
milliseconds:
200
),
child:
Container
(
height:
100.0
,
width:
100.0
,
),
),
],
),
),
);
final
RenderBox
box
=
tester
.
renderObject
<
RenderBox
>(
find
.
byType
(
AnimatedAlign
));
expect
(
box
.
size
.
height
,
equals
(
50.0
));
});
testWidgets
(
'AnimatedAlign null height factor'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
AnimatedAlign
(
alignment:
Alignment
.
center
,
curve:
Curves
.
ease
,
duration:
const
Duration
(
milliseconds:
200
),
child:
Container
(
height:
100.0
,
width:
100.0
,
),
),
],
),
),
);
final
RenderBox
box
=
tester
.
renderObject
<
RenderBox
>(
find
.
byType
(
Container
));
expect
(
box
.
size
,
equals
(
const
Size
(
100.0
,
100
)));
});
testWidgets
(
'AnimatedAlign null widthFactor'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
SizedBox
.
shrink
(
child:
Row
(
mainAxisSize:
MainAxisSize
.
min
,
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
AnimatedAlign
(
alignment:
Alignment
.
center
,
curve:
Curves
.
ease
,
duration:
const
Duration
(
milliseconds:
200
),
child:
Container
(
height:
100.0
,
width:
100.0
,
),
),
],
),
),
),
);
final
RenderBox
box
=
tester
.
renderObject
<
RenderBox
>(
find
.
byType
(
Container
));
expect
(
box
.
size
,
equals
(
const
Size
(
100.0
,
100
)));
});
}
}
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