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
62eebb49
Unverified
Commit
62eebb49
authored
May 27, 2022
by
Markus Aksli
Committed by
GitHub
May 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide `SelectableRegion` text selection toolbar when orientation changes (#104841)
parent
053144b7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
1 deletion
+71
-1
selectable_region.dart
packages/flutter/lib/src/widgets/selectable_region.dart
+31
-1
selectable_region_test.dart
packages/flutter/test/widgets/selectable_region_test.dart
+40
-0
No files found.
packages/flutter/lib/src/widgets/selectable_region.dart
View file @
62eebb49
...
@@ -16,6 +16,7 @@ import 'focus_manager.dart';
...
@@ -16,6 +16,7 @@ import 'focus_manager.dart';
import
'focus_scope.dart'
;
import
'focus_scope.dart'
;
import
'framework.dart'
;
import
'framework.dart'
;
import
'gesture_detector.dart'
;
import
'gesture_detector.dart'
;
import
'media_query.dart'
;
import
'overlay.dart'
;
import
'overlay.dart'
;
import
'selection_container.dart'
;
import
'selection_container.dart'
;
import
'text_editing_intents.dart'
;
import
'text_editing_intents.dart'
;
...
@@ -212,6 +213,8 @@ class _SelectableRegionState extends State<SelectableRegion> with TextSelectionD
...
@@ -212,6 +213,8 @@ class _SelectableRegionState extends State<SelectableRegion> with TextSelectionD
bool
get
_hasSelectionOverlayGeometry
=>
_selectionDelegate
.
value
.
startSelectionPoint
!=
null
bool
get
_hasSelectionOverlayGeometry
=>
_selectionDelegate
.
value
.
startSelectionPoint
!=
null
||
_selectionDelegate
.
value
.
endSelectionPoint
!=
null
;
||
_selectionDelegate
.
value
.
endSelectionPoint
!=
null
;
Orientation
?
_lastOrientation
;
@override
@override
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
...
@@ -228,6 +231,33 @@ class _SelectableRegionState extends State<SelectableRegion> with TextSelectionD
...
@@ -228,6 +231,33 @@ class _SelectableRegionState extends State<SelectableRegion> with TextSelectionD
);
);
}
}
@override
void
didChangeDependencies
()
{
super
.
didChangeDependencies
();
switch
(
defaultTargetPlatform
)
{
case
TargetPlatform
.
android
:
case
TargetPlatform
.
iOS
:
break
;
case
TargetPlatform
.
fuchsia
:
case
TargetPlatform
.
linux
:
case
TargetPlatform
.
macOS
:
case
TargetPlatform
.
windows
:
return
;
}
// Hide the text selection toolbar on mobile when orientation changes.
final
Orientation
orientation
=
MediaQuery
.
of
(
context
).
orientation
;
if
(
_lastOrientation
==
null
)
{
_lastOrientation
=
orientation
;
return
;
}
if
(
orientation
!=
_lastOrientation
)
{
_lastOrientation
=
orientation
;
hideToolbar
(
defaultTargetPlatform
==
TargetPlatform
.
android
);
}
}
@override
@override
void
didUpdateWidget
(
SelectableRegion
oldWidget
)
{
void
didUpdateWidget
(
SelectableRegion
oldWidget
)
{
super
.
didUpdateWidget
(
oldWidget
);
super
.
didUpdateWidget
(
oldWidget
);
...
@@ -703,7 +733,7 @@ class _SelectableRegionState extends State<SelectableRegion> with TextSelectionD
...
@@ -703,7 +733,7 @@ class _SelectableRegionState extends State<SelectableRegion> with TextSelectionD
void
hideToolbar
([
bool
hideHandles
=
true
])
{
void
hideToolbar
([
bool
hideHandles
=
true
])
{
_selectionOverlay
?.
hideToolbar
();
_selectionOverlay
?.
hideToolbar
();
if
(
hideHandles
)
{
if
(
hideHandles
)
{
_selectionOverlay
?.
hide
Toolbar
();
_selectionOverlay
?.
hide
Handles
();
}
}
}
}
...
...
packages/flutter/test/widgets/selectable_region_test.dart
View file @
62eebb49
...
@@ -1100,6 +1100,46 @@ void main() {
...
@@ -1100,6 +1100,46 @@ void main() {
expect
(
clipboardData
[
'text'
],
'thank'
);
expect
(
clipboardData
[
'text'
],
'thank'
);
},
skip:
kIsWeb
);
// [intended] Web uses its native context menu.
},
skip:
kIsWeb
);
// [intended] Web uses its native context menu.
});
});
testWidgets
(
'toolbar is hidden on mobile when orientation changes'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
MaterialApp
(
home:
SelectableRegion
(
focusNode:
FocusNode
(),
selectionControls:
materialTextSelectionControls
,
child:
const
Text
(
'How are you?'
),
),
),
);
addTearDown
(
tester
.
binding
.
window
.
clearPhysicalSizeTestValue
);
final
RenderParagraph
paragraph1
=
tester
.
renderObject
<
RenderParagraph
>(
find
.
descendant
(
of:
find
.
text
(
'How are you?'
),
matching:
find
.
byType
(
RichText
)));
final
TestGesture
gesture
=
await
tester
.
startGesture
(
textOffsetToPosition
(
paragraph1
,
6
));
// at the 'r'
addTearDown
(
gesture
.
removePointer
);
await
tester
.
pump
(
const
Duration
(
milliseconds:
500
));
// `are` is selected.
expect
(
paragraph1
.
selections
[
0
],
const
TextSelection
(
baseOffset:
4
,
extentOffset:
7
));
await
tester
.
pumpAndSettle
();
// Text selection toolbar has appeared.
expect
(
find
.
text
(
'Copy'
),
findsOneWidget
);
// Hide the toolbar by changing orientation.
tester
.
binding
.
window
.
physicalSizeTestValue
=
const
Size
(
1800.0
,
2400.0
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'Copy'
),
findsNothing
);
// Handles should be hidden as well on Android
expect
(
find
.
descendant
(
of:
find
.
byType
(
CompositedTransformFollower
),
matching:
find
.
byType
(
Padding
),
),
defaultTargetPlatform
==
TargetPlatform
.
android
?
findsNothing
:
findsNWidgets
(
2
),
);
},
skip:
kIsWeb
,
// [intended] Web uses its native context menu.
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
android
}),
);
}
}
class
SelectionSpy
extends
LeafRenderObjectWidget
{
class
SelectionSpy
extends
LeafRenderObjectWidget
{
...
...
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