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
ec24a819
Unverified
Commit
ec24a819
authored
Aug 19, 2020
by
Justin McCandless
Committed by
GitHub
Aug 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ClipboardStatusNotifier should handle errors in Clipboard.getData (#64012)
parent
d981fafe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
96 additions
and
10 deletions
+96
-10
text_selection.dart
packages/flutter/lib/src/widgets/text_selection.dart
+19
-8
text_selection_test.dart
packages/flutter/test/widgets/text_selection_test.dart
+77
-2
No files found.
packages/flutter/lib/src/widgets/text_selection.dart
View file @
ec24a819
...
@@ -1512,7 +1512,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
...
@@ -1512,7 +1512,7 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
bool
get
disposed
=>
_disposed
;
bool
get
disposed
=>
_disposed
;
/// Check the [Clipboard] and update [value] if needed.
/// Check the [Clipboard] and update [value] if needed.
void
update
()
{
Future
<
void
>
update
()
async
{
// iOS 14 added a notification that appears when an app accesses the
// iOS 14 added a notification that appears when an app accesses the
// clipboard. To avoid the notification, don't access the clipboard on iOS,
// clipboard. To avoid the notification, don't access the clipboard on iOS,
// and instead always shown the paste button, even when the clipboard is
// and instead always shown the paste button, even when the clipboard is
...
@@ -1532,7 +1532,19 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
...
@@ -1532,7 +1532,19 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
break
;
break
;
}
}
Clipboard
.
getData
(
Clipboard
.
kTextPlain
).
then
((
ClipboardData
data
)
{
ClipboardData
data
;
try
{
data
=
await
Clipboard
.
getData
(
Clipboard
.
kTextPlain
);
}
catch
(
stacktrace
)
{
// In the case of an error from the Clipboard API, set the value to
// unknown so that it will try to update again later.
if
(
_disposed
||
value
==
ClipboardStatus
.
unknown
)
{
return
;
}
value
=
ClipboardStatus
.
unknown
;
return
;
}
final
ClipboardStatus
clipboardStatus
=
data
!=
null
&&
data
.
text
!=
null
&&
data
.
text
.
isNotEmpty
final
ClipboardStatus
clipboardStatus
=
data
!=
null
&&
data
.
text
!=
null
&&
data
.
text
.
isNotEmpty
?
ClipboardStatus
.
pasteable
?
ClipboardStatus
.
pasteable
:
ClipboardStatus
.
notPasteable
;
:
ClipboardStatus
.
notPasteable
;
...
@@ -1540,7 +1552,6 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
...
@@ -1540,7 +1552,6 @@ class ClipboardStatusNotifier extends ValueNotifier<ClipboardStatus> with Widget
return
;
return
;
}
}
value
=
clipboardStatus
;
value
=
clipboardStatus
;
});
}
}
@override
@override
...
...
packages/flutter/test/widgets/text_selection_test.dart
View file @
ec24a819
...
@@ -6,9 +6,34 @@
...
@@ -6,9 +6,34 @@
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'package:flutter/gestures.dart'
show
PointerDeviceKind
;
import
'package:flutter/gestures.dart'
show
PointerDeviceKind
;
import
'package:flutter/widgets.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/widgets.dart'
;
class
MockClipboard
{
MockClipboard
({
this
.
getDataThrows
=
false
,
});
final
bool
getDataThrows
;
Object
_clipboardData
=
<
String
,
dynamic
>{
'text'
:
null
,
};
Future
<
dynamic
>
handleMethodCall
(
MethodCall
methodCall
)
async
{
switch
(
methodCall
.
method
)
{
case
'Clipboard.getData'
:
if
(
getDataThrows
)
{
throw
Exception
();
}
return
_clipboardData
;
case
'Clipboard.setData'
:
_clipboardData
=
methodCall
.
arguments
;
}
}
}
void
main
(
)
{
void
main
(
)
{
int
tapCount
;
int
tapCount
;
...
@@ -608,6 +633,56 @@ void main() {
...
@@ -608,6 +633,56 @@ void main() {
expect
(
hitRect
.
size
.
width
,
lessThan
(
textFieldRect
.
size
.
width
));
expect
(
hitRect
.
size
.
width
,
lessThan
(
textFieldRect
.
size
.
width
));
expect
(
hitRect
.
size
.
height
,
lessThan
(
textFieldRect
.
size
.
height
));
expect
(
hitRect
.
size
.
height
,
lessThan
(
textFieldRect
.
size
.
height
));
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
},
variant:
const
TargetPlatformVariant
(<
TargetPlatform
>{
TargetPlatform
.
iOS
,
TargetPlatform
.
macOS
}));
group
(
'ClipboardStatusNotifier'
,
()
{
group
(
'when Clipboard fails'
,
()
{
setUp
(()
{
final
MockClipboard
mockClipboard
=
MockClipboard
(
getDataThrows:
true
);
SystemChannels
.
platform
.
setMockMethodCallHandler
(
mockClipboard
.
handleMethodCall
);
});
tearDown
(()
{
SystemChannels
.
platform
.
setMockMethodCallHandler
(
null
);
});
test
(
'Clipboard API failure is gracefully recovered from'
,
()
async
{
final
ClipboardStatusNotifier
notifier
=
ClipboardStatusNotifier
();
expect
(
notifier
.
value
,
ClipboardStatus
.
unknown
);
await
expectLater
(
notifier
.
update
(),
completes
);
expect
(
notifier
.
value
,
ClipboardStatus
.
unknown
);
});
});
group
(
'when Clipboard succeeds'
,
()
{
final
MockClipboard
mockClipboard
=
MockClipboard
();
setUp
(()
{
SystemChannels
.
platform
.
setMockMethodCallHandler
(
mockClipboard
.
handleMethodCall
);
});
tearDown
(()
{
SystemChannels
.
platform
.
setMockMethodCallHandler
(
null
);
});
test
(
'update sets value based on clipboard contents'
,
()
async
{
final
ClipboardStatusNotifier
notifier
=
ClipboardStatusNotifier
();
expect
(
notifier
.
value
,
ClipboardStatus
.
unknown
);
await
expectLater
(
notifier
.
update
(),
completes
);
expect
(
notifier
.
value
,
ClipboardStatus
.
notPasteable
);
mockClipboard
.
handleMethodCall
(
const
MethodCall
(
'Clipboard.setData'
,
<
String
,
dynamic
>{
'text'
:
'pasteablestring'
,
},
));
await
expectLater
(
notifier
.
update
(),
completes
);
expect
(
notifier
.
value
,
ClipboardStatus
.
pasteable
);
});
});
});
}
}
class
FakeTextSelectionGestureDetectorBuilderDelegate
implements
TextSelectionGestureDetectorBuilderDelegate
{
class
FakeTextSelectionGestureDetectorBuilderDelegate
implements
TextSelectionGestureDetectorBuilderDelegate
{
...
...
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