更好的选择
跨小部件(文本、图像等)的类似 Web 的文本选择的实验性解决方案。
Better selection 依赖于 super_editor,并深受其启发。它使用了 super_editor 的 SuperSelectableText,该组件允许将文本选择作为参数传递,以及 TapSequenceGestureRecognizer 来支持三击。
此软件包远未稳定,许多 API 在不久的将来可能会发生变化。
限制
- 可滚动支持有限。嵌套滚动视图和作用域内的多个滚动视图可能表现不自然。
- 不支持“多列布局”。在 Row 上使用作用域与在 Web 上的行为大不相同。
- 不支持移动设备
安装
要开始使用,请将 git 依赖项添加到您的 pubspec.yaml 文件中。
better_selection:
git:
url: git://github.com/wilsonowilson/better_selection.git
ref: main
用法
添加 SelectableScope 小部件
在执行任何操作之前,您必须将 SelectableScope 小部件插入到您的窗口小部件树中。您可以将此小部件放置在任何需要进行多文本选择的位置。
class Screen extends StatelessWidget {
const Screen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return SelectableScope(
child: Scaffold(
body: Column(
children: [
...
],
),
),
);
}
}
所有实现 SelectableWidget 的子小部件现在都可以跨作用域进行选择。
默认可选择的小部件
默认情况下,better_selection 自带两个可选择的小部件。
TextSelectable
一个纯文本小部件。也支持富文本。
TextSelectable.plain('Lorem ipsum')
BoxSelectable
一个允许选择其子项的 SelectableWidget。用例包括复制图像和图标。您可以使用 text 参数指定复制的文本。
BoxSelectable(
// Making the copyable text html enables
// inter-application image pasting.
text: '<img src="$imageLink">',
child: Image.network(imageLink),
),
