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
22ea668f
Unverified
Commit
22ea668f
authored
Jun 09, 2020
by
Pierre-Louis
Committed by
GitHub
Jun 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scale input decorator label width (#59010)
parent
01e60a1c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
4 deletions
+58
-4
input_decorator.dart
packages/flutter/lib/src/material/input_decorator.dart
+6
-4
input_decorator_test.dart
packages/flutter/test/material/input_decorator_test.dart
+52
-0
No files found.
packages/flutter/lib/src/material/input_decorator.dart
View file @
22ea668f
...
...
@@ -17,6 +17,7 @@ import 'theme_data.dart';
const
Duration
_kTransitionDuration
=
Duration
(
milliseconds:
200
);
const
Curve
_kTransitionCurve
=
Curves
.
fastOutSlowIn
;
const
double
_kFinalLabelScale
=
0.75
;
// Defines the gap in the InputDecorator's outline border where the
// floating label will appear.
...
...
@@ -981,9 +982,11 @@ class _RenderDecoration extends RenderBox {
+
_boxSize
(
suffix
).
width
+
_boxSize
(
suffixIcon
).
width
+
contentPadding
.
right
));
// Increase the available width for the label when it is scaled down.
final
double
invertedLabelScale
=
lerpDouble
(
1.00
,
1
/
_kFinalLabelScale
,
decoration
.
floatingLabelProgress
);
boxToBaseline
[
label
]
=
_layoutLineBox
(
label
,
boxConstraints
.
copyWith
(
maxWidth:
inputWidth
),
boxConstraints
.
copyWith
(
maxWidth:
inputWidth
*
invertedLabelScale
),
);
boxToBaseline
[
hint
]
=
_layoutLineBox
(
hint
,
...
...
@@ -1452,11 +1455,10 @@ class _RenderDecoration extends RenderBox {
final
bool
isOutlineBorder
=
decoration
.
border
!=
null
&&
decoration
.
border
.
isOutline
;
// Temporary opt-in fix for https://github.com/flutter/flutter/issues/54028
// Center the scaled label relative to the border.
const
double
finalLabelScale
=
0.75
;
final
double
floatingY
=
decoration
.
fixTextFieldOutlineLabel
?
isOutlineBorder
?
(-
labelHeight
*
f
inalLabelScale
)
/
2.0
+
borderWeight
/
2.0
:
contentPadding
.
top
?
isOutlineBorder
?
(-
labelHeight
*
_kF
inalLabelScale
)
/
2.0
+
borderWeight
/
2.0
:
contentPadding
.
top
:
isOutlineBorder
?
-
labelHeight
*
0.25
:
contentPadding
.
top
;
final
double
scale
=
lerpDouble
(
1.0
,
f
inalLabelScale
,
t
);
final
double
scale
=
lerpDouble
(
1.0
,
_kF
inalLabelScale
,
t
);
double
dx
;
switch
(
textDirection
)
{
case
TextDirection
.
rtl
:
...
...
packages/flutter/test/material/input_decorator_test.dart
View file @
22ea668f
...
...
@@ -4069,6 +4069,58 @@ void main() {
expect
(
tester
.
getTopLeft
(
find
.
text
(
'label'
)).
dy
,
20.0
);
});
testWidgets
(
'InputDecorator floating label width scales when focused'
,
(
WidgetTester
tester
)
async
{
final
String
longStringA
=
String
.
fromCharCodes
(
List
<
int
>.
generate
(
200
,
(
_
)
=>
65
));
final
String
longStringB
=
String
.
fromCharCodes
(
List
<
int
>.
generate
(
200
,
(
_
)
=>
66
));
await
tester
.
pumpWidget
(
Center
(
child:
Container
(
width:
100
,
height:
100
,
child:
buildInputDecorator
(
// isFocused: false (default)
isEmpty:
true
,
decoration:
InputDecoration
(
labelText:
longStringA
,
),
),
),
),
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
longStringA
),
paints
..
clipRect
(
rect:
const
Rect
.
fromLTWH
(
0
,
0
,
100.0
,
16.0
)),
);
await
tester
.
pumpWidget
(
Center
(
child:
Container
(
width:
100
,
height:
100
,
child:
buildInputDecorator
(
isFocused:
true
,
isEmpty:
true
,
decoration:
InputDecoration
(
labelText:
longStringB
,
),
),
),
),
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
longStringB
),
// 133.3 is approximately 100 / 0.75 (_kFinalLabelScale)
paints
..
clipRect
(
rect:
const
Rect
.
fromLTWH
(
0
,
0
,
133.0
,
16.0
)),
);
},
skip:
isBrowser
);
// TODO(yjbanov): https://github.com/flutter/flutter/issues/44020
testWidgets
(
'textAlignVertical can be updated'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/56933
const
String
hintText
=
'hint'
;
...
...
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