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
ea343ccc
Commit
ea343ccc
authored
Mar 28, 2019
by
Nizarius
Committed by
xster
Mar 28, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
CupertinoTextField: added ability to change placeholder color (#28001)
parent
3c93b65a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
8 deletions
+55
-8
text_field.dart
packages/flutter/lib/src/cupertino/text_field.dart
+21
-8
text_field_test.dart
packages/flutter/test/cupertino/text_field_test.dart
+34
-0
No files found.
packages/flutter/lib/src/cupertino/text_field.dart
View file @
ea343ccc
...
...
@@ -152,6 +152,10 @@ class CupertinoTextField extends StatefulWidget {
this
.
decoration
=
_kDefaultRoundedBorderDecoration
,
this
.
padding
=
const
EdgeInsets
.
all
(
6.0
),
this
.
placeholder
,
this
.
placeholderStyle
=
const
TextStyle
(
fontWeight:
FontWeight
.
w300
,
color:
_kInactiveTextColor
),
this
.
prefix
,
this
.
prefixMode
=
OverlayVisibilityMode
.
always
,
this
.
suffix
,
...
...
@@ -238,6 +242,17 @@ class CupertinoTextField extends StatefulWidget {
/// main text entry except a lighter font weight and a grey font color.
final
String
placeholder
;
/// The style to use for the placeholder text.
///
/// The [placeholderStyle] is merged with the [style] [TextStyle] when applied
/// to the [placeholder] text. To avoid merging with [style], specify
/// [TextStyle.inherit] as false.
///
/// Defaults to the [style] property with w300 font weight and grey color.
///
/// If specifically set to null, placeholder's style will be the same as [style].
final
TextStyle
placeholderStyle
;
/// An optional [Widget] to display before the text.
final
Widget
prefix
;
...
...
@@ -422,6 +437,7 @@ class CupertinoTextField extends StatefulWidget {
properties
.
add
(
DiagnosticsProperty
<
BoxDecoration
>(
'decoration'
,
decoration
));
properties
.
add
(
DiagnosticsProperty
<
EdgeInsetsGeometry
>(
'padding'
,
padding
));
properties
.
add
(
StringProperty
(
'placeholder'
,
placeholder
));
properties
.
add
(
DiagnosticsProperty
<
TextStyle
>(
'placeholderStyle'
,
placeholderStyle
));
properties
.
add
(
DiagnosticsProperty
<
OverlayVisibilityMode
>(
'prefix'
,
prefix
==
null
?
null
:
prefixMode
));
properties
.
add
(
DiagnosticsProperty
<
OverlayVisibilityMode
>(
'suffix'
,
suffix
==
null
?
null
:
suffixMode
));
properties
.
add
(
DiagnosticsProperty
<
OverlayVisibilityMode
>(
'clearButtonMode'
,
clearButtonMode
));
...
...
@@ -603,9 +619,10 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
);
}
Widget
_addTextDependentAttachments
(
Widget
editableText
,
TextStyle
textStyle
)
{
Widget
_addTextDependentAttachments
(
Widget
editableText
,
TextStyle
textStyle
,
TextStyle
placeholderStyle
)
{
assert
(
editableText
!=
null
);
assert
(
textStyle
!=
null
);
assert
(
placeholderStyle
!=
null
);
// If there are no surrounding widgets, just return the core editable text
// part.
if
(
widget
.
placeholder
==
null
&&
...
...
@@ -640,12 +657,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
widget
.
placeholder
,
maxLines:
1
,
overflow:
TextOverflow
.
ellipsis
,
style:
textStyle
.
merge
(
const
TextStyle
(
color:
_kInactiveTextColor
,
fontWeight:
FontWeight
.
w300
,
),
),
style:
placeholderStyle
),
),
);
...
...
@@ -698,6 +710,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
}
final
CupertinoThemeData
themeData
=
CupertinoTheme
.
of
(
context
);
final
TextStyle
textStyle
=
themeData
.
textTheme
.
textStyle
.
merge
(
widget
.
style
);
final
TextStyle
placeholderStyle
=
textStyle
.
merge
(
widget
.
placeholderStyle
);
final
Brightness
keyboardAppearance
=
widget
.
keyboardAppearance
??
themeData
.
brightness
;
final
Color
cursorColor
=
widget
.
cursorColor
??
themeData
.
primaryColor
;
...
...
@@ -773,7 +786,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
onDragSelectionUpdate:
_handleMouseDragSelectionUpdate
,
onDragSelectionEnd:
_handleMouseDragSelectionEnd
,
behavior:
HitTestBehavior
.
translucent
,
child:
_addTextDependentAttachments
(
paddedEditable
,
textStyle
),
child:
_addTextDependentAttachments
(
paddedEditable
,
textStyle
,
placeholderStyle
),
),
),
),
...
...
packages/flutter/test/cupertino/text_field_test.dart
View file @
ea343ccc
...
...
@@ -399,6 +399,40 @@ void main() {
},
);
testWidgets
(
"placeholderStyle modifies placeholder's style and doesn't affect text's style"
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
CupertinoApp
(
home:
Center
(
child:
CupertinoTextField
(
placeholder:
'placeholder'
,
style:
TextStyle
(
color:
Color
(
0
X00FFFFFF
),
fontWeight:
FontWeight
.
w300
,
),
placeholderStyle:
TextStyle
(
color:
Color
(
0
XAAFFFFFF
),
fontWeight:
FontWeight
.
w600
),
),
),
),
);
final
Text
placeholder
=
tester
.
widget
(
find
.
text
(
'placeholder'
));
expect
(
placeholder
.
style
.
color
,
const
Color
(
0
XAAFFFFFF
));
expect
(
placeholder
.
style
.
fontWeight
,
FontWeight
.
w600
);
await
tester
.
enterText
(
find
.
byType
(
CupertinoTextField
),
'input'
);
await
tester
.
pump
();
final
EditableText
inputText
=
tester
.
widget
(
find
.
text
(
'input'
));
expect
(
inputText
.
style
.
color
,
const
Color
(
0
X00FFFFFF
));
expect
(
inputText
.
style
.
fontWeight
,
FontWeight
.
w300
);
},
);
testWidgets
(
'prefix widget is in front of the text'
,
(
WidgetTester
tester
)
async
{
...
...
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