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
8e978076
Unverified
Commit
8e978076
authored
Mar 29, 2018
by
Hans Muller
Committed by
GitHub
Mar 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for disabling TextField, TextFormField (#16027)
parent
89570732
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
20 deletions
+78
-20
date_and_time_picker_demo.dart
..._gallery/lib/demo/material/date_and_time_picker_demo.dart
+2
-0
text_form_field_demo.dart
...utter_gallery/lib/demo/material/text_form_field_demo.dart
+6
-2
input_decorator.dart
packages/flutter/lib/src/material/input_decorator.dart
+14
-4
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+24
-10
text_form_field.dart
packages/flutter/lib/src/material/text_form_field.dart
+2
-0
input_decorator_test.dart
packages/flutter/test/material/input_decorator_test.dart
+30
-4
No files found.
examples/flutter_gallery/lib/demo/material/date_and_time_picker_demo.dart
View file @
8e978076
...
...
@@ -138,8 +138,10 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
padding:
const
EdgeInsets
.
all
(
16.0
),
children:
<
Widget
>[
new
TextField
(
enabled:
true
,
decoration:
const
InputDecoration
(
labelText:
'Event name'
,
border:
const
OutlineInputBorder
(),
),
style:
Theme
.
of
(
context
).
textTheme
.
display1
,
),
...
...
examples/flutter_gallery/lib/demo/material/text_form_field_demo.dart
View file @
8e978076
...
...
@@ -249,17 +249,21 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
fieldKey:
_passwordFieldKey
,
helperText:
'No more than 8 characters.'
,
labelText:
'Password *'
,
onSaved:
(
String
value
)
{
person
.
password
=
value
;
},
onFieldSubmitted:
(
String
value
)
{
setState
(()
{
person
.
password
=
value
;
});
},
),
const
SizedBox
(
height:
24.0
),
new
TextFormField
(
enabled:
person
.
password
!=
null
&&
person
.
password
.
isNotEmpty
,
decoration:
const
InputDecoration
(
border:
const
UnderlineInputBorder
(),
filled:
true
,
labelText:
'Re-type password'
,
),
maxLength:
8
,
onFieldSubmitted:
(
String
value
)
{
person
.
password
=
value
;
},
obscureText:
true
,
validator:
_validatePassword
,
),
...
...
packages/flutter/lib/src/material/input_decorator.dart
View file @
8e978076
...
...
@@ -1459,6 +1459,9 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
}
Color
_getDefaultIconColor
(
ThemeData
themeData
)
{
if
(!
decoration
.
enabled
)
return
themeData
.
disabledColor
;
switch
(
themeData
.
brightness
)
{
case
Brightness
.
dark
:
return
Colors
.
white70
;
...
...
@@ -1478,7 +1481,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
// i.e. when they appear in place of the empty text field.
TextStyle
_getInlineStyle
(
ThemeData
themeData
)
{
return
themeData
.
textTheme
.
subhead
.
merge
(
widget
.
baseStyle
)
.
copyWith
(
color:
themeData
.
hint
Color
);
.
copyWith
(
color:
decoration
.
enabled
?
themeData
.
hintColor
:
themeData
.
disabled
Color
);
}
TextStyle
_getFloatingLabelStyle
(
ThemeData
themeData
)
{
...
...
@@ -1487,16 +1490,18 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
:
_getActiveColor
(
themeData
);
final
TextStyle
style
=
themeData
.
textTheme
.
subhead
.
merge
(
widget
.
baseStyle
);
return
style
.
copyWith
(
color:
c
olor
)
.
copyWith
(
color:
decoration
.
enabled
?
color
:
themeData
.
disabledC
olor
)
.
merge
(
decoration
.
labelStyle
);
}
TextStyle
_getHelperStyle
(
ThemeData
themeData
)
{
return
themeData
.
textTheme
.
caption
.
copyWith
(
color:
themeData
.
hintColor
).
merge
(
decoration
.
helperStyle
);
final
Color
color
=
decoration
.
enabled
?
themeData
.
hintColor
:
Colors
.
transparent
;
return
themeData
.
textTheme
.
caption
.
copyWith
(
color:
color
).
merge
(
decoration
.
helperStyle
);
}
TextStyle
_getErrorStyle
(
ThemeData
themeData
)
{
return
themeData
.
textTheme
.
caption
.
copyWith
(
color:
themeData
.
errorColor
).
merge
(
decoration
.
errorStyle
);
final
Color
color
=
decoration
.
enabled
?
themeData
.
errorColor
:
Colors
.
transparent
;
return
themeData
.
textTheme
.
caption
.
copyWith
(
color:
color
).
merge
(
decoration
.
errorStyle
);
}
double
get
_borderWeight
{
...
...
@@ -1506,6 +1511,11 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
}
Color
_getBorderColor
(
ThemeData
themeData
)
{
if
(!
decoration
.
enabled
)
{
if
(
decoration
.
filled
==
true
&&
!
decoration
.
border
.
isOutline
)
return
Colors
.
transparent
;
return
themeData
.
disabledColor
;
}
return
decoration
.
errorText
==
null
?
_getActiveColor
(
themeData
)
:
themeData
.
errorColor
;
...
...
packages/flutter/lib/src/material/text_field.dart
View file @
8e978076
...
...
@@ -111,6 +111,7 @@ class TextField extends StatefulWidget {
this
.
onChanged
,
this
.
onSubmitted
,
this
.
inputFormatters
,
this
.
enabled
,
})
:
assert
(
keyboardType
!=
null
),
assert
(
textAlign
!=
null
),
assert
(
autofocus
!=
null
),
...
...
@@ -137,7 +138,7 @@ class TextField extends StatefulWidget {
/// By default, draws a horizontal line under the text field but can be
/// configured to show an icon, label, hint text, and error text.
///
/// S
et this field to
null to remove the decoration entirely (including the
/// S
pecify
null to remove the decoration entirely (including the
/// extra padding introduced by the decoration to save space for the labels).
final
InputDecoration
decoration
;
...
...
@@ -261,6 +262,13 @@ class TextField extends StatefulWidget {
/// Formatters are run in the provided order when the text input changes.
final
List
<
TextInputFormatter
>
inputFormatters
;
/// If false the textfield is "disabled": it ignores taps and its
/// [decoration] is rendered in grey.
///
/// If non-null this property overrides the [decoration]'s
/// [Decoration.enabled] property.
final
bool
enabled
;
@override
_TextFieldState
createState
()
=>
new
_TextFieldState
();
...
...
@@ -299,7 +307,10 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
InputDecoration
_getEffectiveDecoration
()
{
final
InputDecoration
effectiveDecoration
=
(
widget
.
decoration
??
const
InputDecoration
())
.
applyDefaults
(
Theme
.
of
(
context
).
inputDecorationTheme
);
.
applyDefaults
(
Theme
.
of
(
context
).
inputDecorationTheme
)
.
copyWith
(
enabled:
widget
.
enabled
,
);
if
(!
needsCounter
)
return
effectiveDecoration
;
...
...
@@ -495,14 +506,17 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
_controller
.
selection
=
new
TextSelection
.
collapsed
(
offset:
_controller
.
text
.
length
);
_requestKeyboard
();
},
child:
new
GestureDetector
(
behavior:
HitTestBehavior
.
translucent
,
onTapDown:
_handleTapDown
,
onTap:
_handleTap
,
onTapCancel:
_handleTapCancel
,
onLongPress:
_handleLongPress
,
excludeFromSemantics:
true
,
child:
child
,
child:
new
IgnorePointer
(
ignoring:
!(
widget
.
enabled
??
widget
.
decoration
?.
enabled
??
true
),
child:
new
GestureDetector
(
behavior:
HitTestBehavior
.
translucent
,
onTapDown:
_handleTapDown
,
onTap:
_handleTap
,
onTapCancel:
_handleTapCancel
,
onLongPress:
_handleLongPress
,
excludeFromSemantics:
true
,
child:
child
,
),
),
);
}
...
...
packages/flutter/lib/src/material/text_form_field.dart
View file @
8e978076
...
...
@@ -67,6 +67,7 @@ class TextFormField extends FormField<String> {
FormFieldSetter
<
String
>
onSaved
,
FormFieldValidator
<
String
>
validator
,
List
<
TextInputFormatter
>
inputFormatters
,
bool
enabled
,
})
:
assert
(
initialValue
==
null
||
controller
==
null
),
assert
(
keyboardType
!=
null
),
assert
(
textAlign
!=
null
),
...
...
@@ -101,6 +102,7 @@ class TextFormField extends FormField<String> {
onChanged:
field
.
didChange
,
onSubmitted:
onFieldSubmitted
,
inputFormatters:
inputFormatters
,
enabled:
enabled
,
);
},
);
...
...
packages/flutter/test/material/input_decorator_test.dart
View file @
8e978076
...
...
@@ -60,17 +60,21 @@ double getBorderBottom(WidgetTester tester) {
return
box
.
size
.
height
;
}
double
getBorderWeight
(
WidgetTester
tester
)
{
BorderSide
getBorderSide
(
WidgetTester
tester
)
{
if
(!
tester
.
any
(
findBorderPainter
()))
return
0.0
;
return
null
;
final
CustomPaint
customPaint
=
tester
.
widget
(
findBorderPainter
());
final
dynamic
/* _InputBorderPainter */
inputBorderPainter
=
customPaint
.
foregroundPainter
;
final
dynamic
/*_InputBorderTween */
inputBorderTween
=
inputBorderPainter
.
border
;
final
Animation
<
double
>
animation
=
inputBorderPainter
.
borderAnimation
;
final
dynamic
/*_InputBorder */
border
=
inputBorderTween
.
evaluate
(
animation
);
return
border
.
borderSide
.
width
;
return
border
.
borderSide
;
}
double
getBorderWeight
(
WidgetTester
tester
)
=>
getBorderSide
(
tester
)?.
width
;
Color
getBorderColor
(
WidgetTester
tester
)
=>
getBorderSide
(
tester
)?.
color
;
double
getHintOpacity
(
WidgetTester
tester
)
{
final
Opacity
opacityWidget
=
tester
.
widget
<
Opacity
>(
find
.
ancestor
(
...
...
@@ -190,7 +194,8 @@ void main() {
expect
(
getBorderBottom
(
tester
),
56.0
);
expect
(
getBorderWeight
(
tester
),
2.0
);
// enabled: false causes the border to disappear
// enabled: false produces a hairline border if filled: false (the default)
// The widget's size and layout is the same as for enabled: true.
await
tester
.
pumpWidget
(
buildInputDecorator
(
isEmpty:
true
,
...
...
@@ -208,6 +213,27 @@ void main() {
expect
(
tester
.
getTopLeft
(
find
.
text
(
'label'
)).
dy
,
20.0
);
expect
(
tester
.
getBottomLeft
(
find
.
text
(
'label'
)).
dy
,
36.0
);
expect
(
getBorderWeight
(
tester
),
0.0
);
// enabled: false produces a transparent border if filled: true.
// The widget's size and layout is the same as for enabled: true.
await
tester
.
pumpWidget
(
buildInputDecorator
(
isEmpty:
true
,
isFocused:
false
,
decoration:
const
InputDecoration
(
labelText:
'label'
,
enabled:
false
,
filled:
true
,
),
),
);
await
tester
.
pumpAndSettle
();
expect
(
tester
.
getSize
(
find
.
byType
(
InputDecorator
)),
const
Size
(
800.0
,
56.0
));
expect
(
tester
.
getTopLeft
(
find
.
text
(
'text'
)).
dy
,
28.0
);
expect
(
tester
.
getBottomLeft
(
find
.
text
(
'text'
)).
dy
,
44.0
);
expect
(
tester
.
getTopLeft
(
find
.
text
(
'label'
)).
dy
,
20.0
);
expect
(
tester
.
getBottomLeft
(
find
.
text
(
'label'
)).
dy
,
36.0
);
expect
(
getBorderColor
(
tester
),
Colors
.
transparent
);
});
// Overall height for this InputDecorator is 40.0dps
...
...
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