Center( child: SelectableText.rich( TextSpan( children: <TextSpan>[ TextSpan(text: 'Flutter', style: TextStyle(color: Colors.blue)), TextSpan(text: 'Devs', style: TextStyle(color: Colors.black)), TextSpan(text: '.com', style: TextStyle(color: Colors.red)), ], ), style: TextStyle( fontWeight: FontWeight.bold, fontSize: 48), textAlign: TextAlign.center, onTap: () => print('Tapped'), toolbarOptions: ToolbarOptions(copy: true, selectAll: false), showCursor: true, cursorWidth: 2, cursorColor: Colors.black, cursorRadius: Radius.circular(5), ), )
SelectableText小部件的一些属性包括:
data:此属性是一个重要的属性,其中必须显示作为SelectableText的功能出现的数据。要显示的文本。
onTap:此属性用于回调函数,该函数在有人点击SelectableText的Text时终止。当然,点击会打开全选/复制选项。如果你需要进行不同的练习,请在这里强调取代它们。
textSpan:此属性用作SelectableText的组件。这允许您选择TextSpan,它可以保存SelectableText小部件上的各种文本。
autofocus:如果没有其他内容已经聚焦,则使用该属性来确定是否应该聚焦自己。默认为false。
maxLines:此属性用于计算文本要跨越的最大行数,必要时换行。
toolbarOptions:此属性用于使用给定选项创建工具栏配置。如果未显式设置所有选项,则默认为false。
enableInteractiveSelection:此属性用于在长按时是否选择文本并显示复制/粘贴/剪切菜单。默认为true。