-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Description
With #92295, it's now possible to put WidgetSpans into SelectableText. It should be possible to copy that content to the clipboard in an intuitive way. Currently, any WidgetSpan copied to the clipboard will appear as a Unicode OBJ character (U+FFFC).
Example
For example, in this app, copying the image in this example app should do something useful like copy the src, the semanticLabel, or the image itself. Or, the developer should be able to specify what gets copied.
Example App
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Center(
child: SelectableText.rich(
TextSpan(
children: <InlineSpan>[
WidgetSpan(
child: Image.network(
'https://flutter.dev/assets/images/shared/brand/flutter/logo/flutter-lockup.png',
semanticLabel: 'Flutter',
),
),
],
),
),
),
),
);
}
}Possible Solutions
Either
- Flutter should automatically try to figure out the best thing to copy (
src,semanticLabel, or the image in the example).
And/or
- Flutter should allow the developer to specify what should be copied.
There is another Github issue about supporting a rich text clipboard (#23603). Ideally, with that feature available, copying a WidgetSpan should also copy rich content, such as the image itself in the example above.
Advanced: Pasting WidgetSpans
Flutter currently doesn't support WidgetSpans in high level text editing widgets like TextField, though it's possible to hack an EditableText to take WidgetSpans. If we want to support this, we have to consider what happens when a user copies and then pastes a WidgetSpan. Ideally, it should duplicate the WidgetSpan in the new location.
Should that work across Flutter apps as well? Maybe we need to create a Flutter clipboard content type.
