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
c825fb19
Unverified
Commit
c825fb19
authored
Sep 20, 2022
by
LongCatIsLooong
Committed by
GitHub
Sep 20, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix `InputDecorator` child vertical alignment (#112003)
parent
91c0eb3e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
9 deletions
+56
-9
input_decorator.dart
packages/flutter/lib/src/material/input_decorator.dart
+8
-9
input_decorator_test.dart
packages/flutter/test/material/input_decorator_test.dart
+48
-0
No files found.
packages/flutter/lib/src/material/input_decorator.dart
View file @
c825fb19
...
...
@@ -1114,15 +1114,13 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
+
topHeight
+
inputInternalBaseline
+
baselineAdjustment
+
interactiveAdjustment
;
final
double
maxContentHeight
=
containerHeight
-
contentPadding
.
top
-
topHeight
-
contentPadding
.
bottom
;
+
interactiveAdjustment
+
densityOffset
.
dy
/
2.0
;
final
double
maxContentHeight
=
containerHeight
-
contentPadding
.
vertical
-
topHeight
-
densityOffset
.
dy
;
final
double
alignableHeight
=
fixAboveInput
+
inputHeight
+
fixBelowInput
;
final
double
maxVerticalOffset
=
maxContentHeight
-
alignableHeight
;
final
double
textAlignVerticalOffset
=
maxVerticalOffset
*
textAlignVerticalFactor
;
final
double
inputBaseline
=
topInputBaseline
+
textAlignVerticalOffset
+
densityOffset
.
dy
/
2.0
;
final
double
inputBaseline
=
topInputBaseline
+
textAlignVerticalOffset
;
// The three main alignments for the baseline when an outline is present are
//
...
...
@@ -1302,7 +1300,7 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
@override
double
computeDistanceToActualBaseline
(
TextBaseline
baseline
)
{
return
_boxParentData
(
input
!).
offset
.
dy
+
input
!.
computeDistanceToActualBaseline
(
baseline
)!
;
return
_boxParentData
(
input
!).
offset
.
dy
+
(
input
?.
computeDistanceToActualBaseline
(
baseline
)
??
0.0
)
;
}
// Records where the label was painted.
...
...
@@ -1325,12 +1323,13 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
final
double
overallWidth
=
constraints
.
maxWidth
;
final
double
overallHeight
=
layout
.
containerHeight
+
layout
.
subtextHeight
;
final
RenderBox
?
container
=
this
.
container
;
if
(
container
!=
null
)
{
final
BoxConstraints
containerConstraints
=
BoxConstraints
.
tightFor
(
height:
layout
.
containerHeight
,
width:
overallWidth
-
_boxSize
(
icon
).
width
,
);
container
!
.
layout
(
containerConstraints
,
parentUsesSize:
true
);
container
.
layout
(
containerConstraints
,
parentUsesSize:
true
);
final
double
x
;
switch
(
textDirection
)
{
case
TextDirection
.
rtl
:
...
...
@@ -1340,7 +1339,7 @@ class _RenderDecoration extends RenderBox with SlottedContainerRenderObjectMixin
x
=
_boxSize
(
icon
).
width
;
break
;
}
_boxParentData
(
container
!
).
offset
=
Offset
(
x
,
0.0
);
_boxParentData
(
container
).
offset
=
Offset
(
x
,
0.0
);
}
late
double
height
;
...
...
packages/flutter/test/material/input_decorator_test.dart
View file @
c825fb19
...
...
@@ -2290,6 +2290,54 @@ void main() {
// In between the center and bottom aligned cases.
expect
(
tester
.
getTopLeft
(
find
.
text
(
text
)).
dy
,
moreOrLessEquals
(
useMaterial3
?
497.9375
:
498.5
,
epsilon:
.
0001
));
});
testWidgets
(
'works with density and content padding'
,
(
WidgetTester
tester
)
async
{
const
Key
key
=
Key
(
'child'
);
const
Key
containerKey
=
Key
(
'container'
);
const
double
totalHeight
=
100.0
;
const
double
childHeight
=
20.0
;
const
VisualDensity
visualDensity
=
VisualDensity
(
vertical:
VisualDensity
.
maximumDensity
);
const
EdgeInsets
contentPadding
=
EdgeInsets
.
only
(
top:
6
,
bottom:
14
);
await
tester
.
pumpWidget
(
Center
(
child:
SizedBox
(
key:
containerKey
,
height:
totalHeight
,
child:
buildInputDecorator
(
useMaterial3:
useMaterial3
,
// isEmpty: false (default)
// isFocused: false (default)
expands:
true
,
decoration:
const
InputDecoration
(
border:
InputBorder
.
none
,
contentPadding:
contentPadding
,
),
textAlignVertical:
TextAlignVertical
.
center
,
visualDensity:
visualDensity
,
child:
const
SizedBox
(
key:
key
,
height:
childHeight
),
),
),
),
);
// Vertical components: contentPadding.vertical, densityOffset.y, child
final
double
childVerticalSpaceAffordance
=
totalHeight
-
visualDensity
.
baseSizeAdjustment
.
dy
-
contentPadding
.
vertical
;
// TextAlignVertical.center is specified so `child` needs to be centered
// in the avaiable space.
final
double
childMargin
=
(
childVerticalSpaceAffordance
-
childHeight
)
/
2
;
final
double
childTop
=
visualDensity
.
baseSizeAdjustment
.
dy
/
2.0
+
contentPadding
.
top
+
childMargin
;
expect
(
tester
.
getTopLeft
(
find
.
byKey
(
key
)).
dy
,
tester
.
getTopLeft
(
find
.
byKey
(
containerKey
)).
dy
+
childTop
,
);
});
});
group
(
'outline border'
,
()
{
...
...
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