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
96ca0e27
Unverified
Commit
96ca0e27
authored
Sep 15, 2020
by
Pedro Massango
Committed by
GitHub
Sep 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add onSelectionChanged into SelectableText widget (#65320)
parent
dfd0c627
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
0 deletions
+40
-0
selectable_text.dart
packages/flutter/lib/src/material/selectable_text.dart
+9
-0
editable_text.dart
packages/flutter/lib/src/widgets/editable_text.dart
+2
-0
selectable_text_test.dart
packages/flutter/test/widgets/selectable_text_test.dart
+29
-0
No files found.
packages/flutter/lib/src/material/selectable_text.dart
View file @
96ca0e27
...
@@ -199,6 +199,7 @@ class SelectableText extends StatefulWidget {
...
@@ -199,6 +199,7 @@ class SelectableText extends StatefulWidget {
this
.
scrollPhysics
,
this
.
scrollPhysics
,
this
.
textHeightBehavior
,
this
.
textHeightBehavior
,
this
.
textWidthBasis
,
this
.
textWidthBasis
,
this
.
onSelectionChanged
,
})
:
assert
(
showCursor
!=
null
),
})
:
assert
(
showCursor
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
dragStartBehavior
!=
null
),
assert
(
dragStartBehavior
!=
null
),
...
@@ -250,6 +251,7 @@ class SelectableText extends StatefulWidget {
...
@@ -250,6 +251,7 @@ class SelectableText extends StatefulWidget {
this
.
scrollPhysics
,
this
.
scrollPhysics
,
this
.
textHeightBehavior
,
this
.
textHeightBehavior
,
this
.
textWidthBasis
,
this
.
textWidthBasis
,
this
.
onSelectionChanged
,
})
:
assert
(
showCursor
!=
null
),
})
:
assert
(
showCursor
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
autofocus
!=
null
),
assert
(
dragStartBehavior
!=
null
),
assert
(
dragStartBehavior
!=
null
),
...
@@ -392,6 +394,9 @@ class SelectableText extends StatefulWidget {
...
@@ -392,6 +394,9 @@ class SelectableText extends StatefulWidget {
/// {@macro flutter.painting.textPainter.textWidthBasis}
/// {@macro flutter.painting.textPainter.textWidthBasis}
final
TextWidthBasis
textWidthBasis
;
final
TextWidthBasis
textWidthBasis
;
/// {@macro flutter.widgets.editableText.onSelectionChanged}
final
SelectionChangedCallback
onSelectionChanged
;
@override
@override
_SelectableTextState
createState
()
=>
_SelectableTextState
();
_SelectableTextState
createState
()
=>
_SelectableTextState
();
...
@@ -494,6 +499,10 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
...
@@ -494,6 +499,10 @@ class _SelectableTextState extends State<SelectableText> with AutomaticKeepAlive
});
});
}
}
if
(
widget
.
onSelectionChanged
!=
null
)
{
widget
.
onSelectionChanged
(
selection
,
cause
);
}
switch
(
Theme
.
of
(
context
).
platform
)
{
switch
(
Theme
.
of
(
context
).
platform
)
{
case
TargetPlatform
.
iOS
:
case
TargetPlatform
.
iOS
:
case
TargetPlatform
.
macOS
:
case
TargetPlatform
.
macOS
:
...
...
packages/flutter/lib/src/widgets/editable_text.dart
View file @
96ca0e27
...
@@ -1044,8 +1044,10 @@ class EditableText extends StatefulWidget {
...
@@ -1044,8 +1044,10 @@ class EditableText extends StatefulWidget {
/// {@endtemplate}
/// {@endtemplate}
final
AppPrivateCommandCallback
onAppPrivateCommand
;
final
AppPrivateCommandCallback
onAppPrivateCommand
;
/// {@template flutter.widgets.editableText.onSelectionChanged}
/// Called when the user changes the selection of text (including the cursor
/// Called when the user changes the selection of text (including the cursor
/// location).
/// location).
/// {@endtemplate}
final
SelectionChangedCallback
onSelectionChanged
;
final
SelectionChangedCallback
onSelectionChanged
;
/// {@macro flutter.widgets.textSelection.onSelectionHandleTapped}
/// {@macro flutter.widgets.textSelection.onSelectionHandleTapped}
...
...
packages/flutter/test/widgets/selectable_text_test.dart
View file @
96ca0e27
...
@@ -4012,4 +4012,33 @@ void main() {
...
@@ -4012,4 +4012,33 @@ void main() {
expect
(
state
.
selectionOverlay
.
handlesAreVisible
,
isFalse
);
expect
(
state
.
selectionOverlay
.
handlesAreVisible
,
isFalse
);
}
}
});
});
testWidgets
(
'onSelectionChanged is called when selection changes'
,
(
WidgetTester
tester
)
async
{
int
onSelectionChangedCallCount
=
0
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
SelectableText
(
'abc def ghi'
,
onSelectionChanged:
(
TextSelection
selection
,
SelectionChangedCause
cause
)
{
onSelectionChangedCallCount
+=
1
;
},
),
),
),
);
// Long press to select 'abc'.
final
Offset
aLocation
=
textOffsetToPosition
(
tester
,
1
);
await
tester
.
longPressAt
(
aLocation
);
await
tester
.
pump
();
expect
(
onSelectionChangedCallCount
,
equals
(
1
));
// Tap on 'Select all' option to select the whole text.
await
tester
.
longPressAt
(
textOffsetToPosition
(
tester
,
5
));
await
tester
.
pump
();
await
tester
.
tap
(
find
.
text
(
'Select all'
));
expect
(
onSelectionChangedCallCount
,
equals
(
2
));
});
}
}
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