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
db0b249f
Unverified
Commit
db0b249f
authored
Jul 26, 2021
by
Renzo Olivares
Committed by
GitHub
Jul 26, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add label widget parameter to InputDecoration (#86810)
parent
ccc72fa5
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
485 additions
and
13 deletions
+485
-13
input_decorator.dart
packages/flutter/lib/src/material/input_decorator.dart
+61
-4
input_decorator_test.dart
packages/flutter/test/material/input_decorator_test.dart
+424
-9
No files found.
packages/flutter/lib/src/material/input_decorator.dart
View file @
db0b249f
...
...
@@ -2090,7 +2090,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
// hint would.
bool
get
_hasInlineLabel
{
return
!
widget
.
_labelShouldWithdraw
&&
decoration
!.
labelText
!=
null
&&
(
decoration
!.
labelText
!=
null
||
decoration
!.
label
!=
null
)
&&
decoration
!.
floatingLabelBehavior
!=
FloatingLabelBehavior
.
always
;
}
...
...
@@ -2205,7 +2205,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
final
TextStyle
inlineLabelStyle
=
themeData
.
fixTextFieldOutlineLabel
?
inlineStyle
.
merge
(
decoration
!.
labelStyle
).
copyWith
(
height:
1
)
:
inlineStyle
.
merge
(
decoration
!.
labelStyle
);
final
Widget
?
label
=
decoration
!.
labelText
==
null
?
null
:
_Shaker
(
final
Widget
?
label
=
decoration
!.
labelText
==
null
&&
decoration
!.
label
==
null
?
null
:
_Shaker
(
animation:
_shakingLabelController
.
view
,
child:
AnimatedOpacity
(
duration:
_kTransitionDuration
,
...
...
@@ -2217,7 +2217,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
style:
widget
.
_labelShouldWithdraw
?
_getFloatingLabelStyle
(
themeData
)
:
inlineLabelStyle
,
child:
Text
(
child:
decoration
!.
label
??
Text
(
decoration
!.
labelText
!,
overflow:
TextOverflow
.
ellipsis
,
textAlign:
textAlign
,
...
...
@@ -2521,6 +2521,7 @@ class InputDecoration {
/// Similarly, only one of [suffix] and [suffixText] can be specified.
const
InputDecoration
({
this
.
icon
,
this
.
label
,
this
.
labelText
,
this
.
labelStyle
,
this
.
floatingLabelStyle
,
...
...
@@ -2566,6 +2567,7 @@ class InputDecoration {
this
.
alignLabelWithHint
,
this
.
constraints
,
})
:
assert
(
enabled
!=
null
),
assert
(!(
label
!=
null
&&
labelText
!=
null
),
'Declaring both label and labelText is not supported.'
),
assert
(!(
prefix
!=
null
&&
prefixText
!=
null
),
'Declaring both prefix and prefixText is not supported.'
),
assert
(!(
suffix
!=
null
&&
suffixText
!=
null
),
'Declaring both suffix and suffixText is not supported.'
);
...
...
@@ -2587,6 +2589,7 @@ class InputDecoration {
this
.
enabled
=
true
,
})
:
assert
(
enabled
!=
null
),
icon
=
null
,
label
=
null
,
labelText
=
null
,
labelStyle
=
null
,
floatingLabelStyle
=
null
,
...
...
@@ -2639,13 +2642,62 @@ class InputDecoration {
/// See [Icon], [ImageIcon].
final
Widget
?
icon
;
///
Tex
t that describes the input field.
///
Optional widge
t that describes the input field.
///
/// {@template flutter.material.inputDecoration.label}
/// When the input field is empty and unfocused, the label is displayed on
/// top of the input field (i.e., at the same location on the screen where
/// text may be entered in the input field). When the input field receives
/// focus (or if the field is non-empty), the label moves above (i.e.,
/// vertically adjacent to) the input field.
/// {@endtemplate}
///
/// This can be used, for example, to add multiple [TextStyle]'s to a label that would
/// otherwise be specified using [labelText], which only takes one [TextStyle].
///
/// {@tool dartpad --template=stateless_widget_scaffold}
///
/// This example shows a `TextField` with a [Text.rich] widget as the [label].
/// The widget contains multiple [Text] widgets with different [TextStyle]'s.
///
/// ```dart
/// Widget build(BuildContext context) {
/// return const Center(
/// child: TextField(
/// decoration: InputDecoration(
/// label: Text.rich(
/// TextSpan(
/// children: <InlineSpan>[
/// WidgetSpan(
/// child: Text(
/// 'Username',
/// ),
/// ),
/// WidgetSpan(
/// child: Text(
/// '*',
/// style: TextStyle(color: Colors.red),
/// ),
/// ),
/// ],
/// ),
/// ),
/// ),
/// ),
/// );
/// }
/// ```
/// {@end-tool}
///
/// Only one of [label] and [labelText] can be specified.
final
Widget
?
label
;
/// Optional text that describes the input field.
///
/// {@macro flutter.material.inputDecoration.label}
///
/// If a more elaborate label is required, consider using [label] instead.
/// Only one of [label] and [labelText] can be specified.
final
String
?
labelText
;
/// The style to use for the [labelText] when the label is on top of the
...
...
@@ -3324,6 +3376,7 @@ class InputDecoration {
/// by the new values.
InputDecoration
copyWith
({
Widget
?
icon
,
Widget
?
label
,
String
?
labelText
,
TextStyle
?
labelStyle
,
TextStyle
?
floatingLabelStyle
,
...
...
@@ -3371,6 +3424,7 @@ class InputDecoration {
})
{
return
InputDecoration
(
icon:
icon
??
this
.
icon
,
label:
label
??
this
.
label
,
labelText:
labelText
??
this
.
labelText
,
labelStyle:
labelStyle
??
this
.
labelStyle
,
floatingLabelStyle:
floatingLabelStyle
??
this
.
floatingLabelStyle
,
...
...
@@ -3462,6 +3516,7 @@ class InputDecoration {
return
false
;
return
other
is
InputDecoration
&&
other
.
icon
==
icon
&&
other
.
label
==
label
&&
other
.
labelText
==
labelText
&&
other
.
labelStyle
==
labelStyle
&&
other
.
floatingLabelStyle
==
floatingLabelStyle
...
...
@@ -3512,6 +3567,7 @@ class InputDecoration {
int
get
hashCode
{
final
List
<
Object
?>
values
=
<
Object
?>[
icon
,
label
,
labelText
,
floatingLabelStyle
,
labelStyle
,
...
...
@@ -3566,6 +3622,7 @@ class InputDecoration {
String
toString
()
{
final
List
<
String
>
description
=
<
String
>[
if
(
icon
!=
null
)
'icon:
$icon
'
,
if
(
label
!=
null
)
'label:
$label
'
,
if
(
labelText
!=
null
)
'labelText: "
$labelText
"'
,
if
(
floatingLabelStyle
!=
null
)
'floatingLabelStyle: "
$floatingLabelStyle
"'
,
if
(
helperText
!=
null
)
'helperText: "
$helperText
"'
,
...
...
packages/flutter/test/material/input_decorator_test.dart
View file @
db0b249f
This diff is collapsed.
Click to expand it.
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