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
a14b4f62
Commit
a14b4f62
authored
Jul 20, 2018
by
Norbert Kozsir
Committed by
Michael Goderbauer
Jul 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Making the space between keyboard and text-field when the keyboard pops up a variable. (#18562)
parent
f0639bb0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
125 additions
and
4 deletions
+125
-4
text_field.dart
packages/flutter/lib/src/material/text_field.dart
+13
-0
text_form_field.dart
packages/flutter/lib/src/material/text_form_field.dart
+3
-0
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+20
-3
editable_text_show_on_screen_test.dart
...utter/test/widgets/editable_text_show_on_screen_test.dart
+89
-1
No files found.
packages/flutter/lib/src/material/text_field.dart
View file @
a14b4f62
...
...
@@ -118,6 +118,7 @@ class TextField extends StatefulWidget {
this
.
inputFormatters
,
this
.
enabled
,
this
.
keyboardAppearance
,
this
.
scrollPadding
=
const
EdgeInsets
.
all
(
20.0
),
})
:
assert
(
keyboardType
!=
null
),
assert
(
textInputAction
!=
null
),
assert
(
textAlign
!=
null
),
...
...
@@ -125,6 +126,7 @@ class TextField extends StatefulWidget {
assert
(
obscureText
!=
null
),
assert
(
autocorrect
!=
null
),
assert
(
maxLengthEnforced
!=
null
),
assert
(
scrollPadding
!=
null
),
assert
(
maxLines
==
null
||
maxLines
>
0
),
assert
(
maxLength
==
null
||
maxLength
>
0
),
keyboardType
=
maxLines
==
1
?
keyboardType
:
TextInputType
.
multiline
,
...
...
@@ -319,6 +321,16 @@ class TextField extends StatefulWidget {
/// If unset, defaults to the brightness of [ThemeData.primaryColorBrightness].
final
Brightness
keyboardAppearance
;
/// Configures padding to edges surrounding a [Scrollable] when the Textfield scrolls into view.
///
/// When this widget receives focus and is not completely visible (for example scrolled partially
/// off the screen or overlapped by the keyboard)
/// then it will attempt to make itself visible by scrolling a surrounding [Scrollable], if one is present.
/// This value controls how far from the edges of a [Scrollable] the TextField will be positioned after the scroll.
///
/// Defaults to EdgeInserts.all(20.0).
final
EdgeInsets
scrollPadding
;
@override
_TextFieldState
createState
()
=>
new
_TextFieldState
();
...
...
@@ -541,6 +553,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
onSelectionChanged:
_handleSelectionChanged
,
inputFormatters:
formatters
,
rendererIgnoresPointer:
true
,
scrollPadding:
widget
.
scrollPadding
,
keyboardAppearance:
keyboardAppearance
,
),
);
...
...
packages/flutter/lib/src/material/text_form_field.dart
View file @
a14b4f62
...
...
@@ -73,6 +73,7 @@ class TextFormField extends FormField<String> {
List
<
TextInputFormatter
>
inputFormatters
,
bool
enabled
,
Brightness
keyboardAppearance
,
EdgeInsets
scrollPadding
=
const
EdgeInsets
.
all
(
20.0
),
})
:
assert
(
initialValue
==
null
||
controller
==
null
),
assert
(
keyboardType
!=
null
),
assert
(
textInputAction
!=
null
),
...
...
@@ -82,6 +83,7 @@ class TextFormField extends FormField<String> {
assert
(
autocorrect
!=
null
),
assert
(
autovalidate
!=
null
),
assert
(
maxLengthEnforced
!=
null
),
assert
(
scrollPadding
!=
null
),
assert
(
maxLines
==
null
||
maxLines
>
0
),
assert
(
maxLength
==
null
||
maxLength
>
0
),
super
(
...
...
@@ -114,6 +116,7 @@ class TextFormField extends FormField<String> {
onSubmitted:
onFieldSubmitted
,
inputFormatters:
inputFormatters
,
enabled:
enabled
,
scrollPadding:
scrollPadding
,
keyboardAppearance:
keyboardAppearance
,
);
},
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
a14b4f62
...
...
@@ -211,6 +211,7 @@ class EditableText extends StatefulWidget {
this
.
rendererIgnoresPointer
=
false
,
this
.
cursorWidth
=
1.0
,
this
.
cursorRadius
,
this
.
scrollPadding
=
const
EdgeInsets
.
all
(
20.0
),
this
.
keyboardAppearance
=
Brightness
.
light
,
})
:
assert
(
controller
!=
null
),
assert
(
focusNode
!=
null
),
...
...
@@ -222,6 +223,7 @@ class EditableText extends StatefulWidget {
assert
(
maxLines
==
null
||
maxLines
>
0
),
assert
(
autofocus
!=
null
),
assert
(
rendererIgnoresPointer
!=
null
),
assert
(
scrollPadding
!=
null
),
keyboardType
=
keyboardType
??
(
maxLines
==
1
?
TextInputType
.
text
:
TextInputType
.
multiline
),
inputFormatters
=
maxLines
==
1
?
(
...
...
@@ -387,6 +389,16 @@ class EditableText extends StatefulWidget {
/// Defaults to [Brightness.light].
final
Brightness
keyboardAppearance
;
/// Configures padding to edges surrounding a [Scrollable] when the Textfield scrolls into view.
///
/// When this widget receives focus and is not completely visible (for example scrolled partially
/// off the screen or overlapped by the keyboard)
/// then it will attempt to make itself visible by scrolling a surrounding [Scrollable], if one is present.
/// This value controls how far from the edges of a [Scrollable] the TextField will be positioned after the scroll.
///
/// Defaults to EdgeInserts.all(20.0).
final
EdgeInsets
scrollPadding
;
@override
EditableTextState
createState
()
=>
new
EditableTextState
();
...
...
@@ -579,7 +591,6 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
inputType:
widget
.
keyboardType
,
obscureText:
widget
.
obscureText
,
autocorrect:
widget
.
autocorrect
,
keyboardAppearance:
widget
.
keyboardAppearance
,
inputAction:
widget
.
keyboardType
==
TextInputType
.
multiline
?
TextInputAction
.
newline
:
widget
.
textInputAction
,
...
...
@@ -702,9 +713,15 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
curve:
_caretAnimationCurve
,
);
final
Rect
newCaretRect
=
_getCaretRectAtScrollOffset
(
_currentCaretRect
,
scrollOffsetForCaret
);
// Enlarge newCaretRect by scrollPadding to ensure that caret is not positioned directly at the edge after scrolling.
final
Rect
inflatedRect
=
Rect
.
fromLTRB
(
newCaretRect
.
left
-
widget
.
scrollPadding
.
left
,
newCaretRect
.
top
-
widget
.
scrollPadding
.
top
,
newCaretRect
.
right
+
widget
.
scrollPadding
.
right
,
newCaretRect
.
bottom
+
widget
.
scrollPadding
.
bottom
);
_editableKey
.
currentContext
.
findRenderObject
().
showOnScreen
(
// Inflate ensures that caret is not positioned directly at the edge.
rect:
newCaretRect
.
inflate
(
20.0
),
rect:
inflatedRect
,
duration:
_caretAnimationDuration
,
curve:
_caretAnimationCurve
,
);
...
...
packages/flutter/test/widgets/editable_text_show_on_screen_test.dart
View file @
a14b4f62
...
...
@@ -51,6 +51,51 @@ void main() {
expect
(
scrollController
.
offset
,
0.0
);
});
testWidgets
(
'tapping on a partly visible editable brings it fully on screen with scrollInsets'
,
(
WidgetTester
tester
)
async
{
final
ScrollController
scrollController
=
new
ScrollController
();
final
TextEditingController
controller
=
new
TextEditingController
();
final
FocusNode
focusNode
=
new
FocusNode
();
await
tester
.
pumpWidget
(
new
MaterialApp
(
home:
new
Center
(
child:
new
Container
(
height:
300.0
,
child:
new
ListView
(
controller:
scrollController
,
children:
<
Widget
>[
new
Container
(
height:
200.0
,
),
new
EditableText
(
scrollPadding:
const
EdgeInsets
.
all
(
50.0
),
controller:
controller
,
focusNode:
focusNode
,
style:
textStyle
,
cursorColor:
cursorColor
,
),
new
Container
(
height:
850.0
,
),
],
),
),
),
));
// Scroll the EditableText half off screen.
final
RenderBox
render
=
tester
.
renderObject
(
find
.
byType
(
EditableText
));
scrollController
.
jumpTo
(
200
+
render
.
size
.
height
/
2
);
await
tester
.
pumpAndSettle
();
expect
(
scrollController
.
offset
,
200
+
render
.
size
.
height
/
2
);
await
tester
.
showKeyboard
(
find
.
byType
(
EditableText
));
await
tester
.
pumpAndSettle
();
// Container above the text is 200 in height, the scrollInsets are 50
// Tolerance of 5 units (The actual value was 152.0 in the current tests instead of 150.0)
expect
(
scrollController
.
offset
,
lessThan
(
200.0
-
50.0
+
5.0
));
expect
(
scrollController
.
offset
,
greaterThan
(
200.0
-
50.0
-
5.0
));
});
testWidgets
(
'editable comes back on screen when entering text while it is off-screen'
,
(
WidgetTester
tester
)
async
{
final
ScrollController
scrollController
=
new
ScrollController
(
initialScrollOffset:
100.0
);
final
TextEditingController
controller
=
new
TextEditingController
();
...
...
@@ -145,4 +190,47 @@ void main() {
expect
(
render
.
size
.
height
,
greaterThan
(
500.0
));
expect
(
scrollController
.
offset
,
greaterThan
(
0.0
));
});
testWidgets
(
'scrolls into view with scrollInserts after the keyboard pops up'
,
(
WidgetTester
tester
)
async
{
final
ScrollController
scrollController
=
new
ScrollController
();
final
TextEditingController
controller
=
new
TextEditingController
();
final
FocusNode
focusNode
=
new
FocusNode
();
const
Key
container
=
const
Key
(
'container'
);
await
tester
.
pumpWidget
(
new
MaterialApp
(
home:
new
Align
(
alignment:
Alignment
.
bottomCenter
,
child:
new
Container
(
height:
300.0
,
child:
new
ListView
(
controller:
scrollController
,
children:
<
Widget
>[
new
Container
(
key:
container
,
height:
200.0
,
),
new
EditableText
(
scrollPadding:
const
EdgeInsets
.
only
(
bottom:
300.0
),
controller:
controller
,
focusNode:
focusNode
,
style:
textStyle
,
cursorColor:
cursorColor
,
),
new
Container
(
height:
400.0
,
),
],
),
),
),
));
expect
(
scrollController
.
offset
,
0.0
);
await
tester
.
showKeyboard
(
find
.
byType
(
EditableText
));
await
tester
.
pumpAndSettle
();
expect
(
scrollController
.
offset
,
greaterThan
(
0.0
));
expect
(
find
.
byKey
(
container
),
findsNothing
);
});
}
\ No newline at end of file
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