SelectableText Examples

The SelectableText widget displays a string of text using a single style. Depending on the layout constraints, the string might break across multiple lines or display all on one line.

You can use the SelectableText widget to display a string of text that you want the user to be able to select and copy. For example, you might use the SelectableText widget to display a block of code. The SelectableText widget is similar to the Text widget, but it adds support for selecting and copying text.

const SelectableText(
  'Simple selectable text',
),
const SelectableText(
  'Selectable text with cursor',
  cursorColor: Colors.red,
  cursorWidth: 24,
  cursorHeight: 24,
  style: TextStyle(fontWeight: FontWeight.bold),
),
const SelectableText.rich(
  TextSpan(
    text: 'Rich ',
    children: <TextSpan>[
      TextSpan(text: ' selectable ', style: TextStyle(fontStyle: FontStyle.italic, color: Colors.red)),
      TextSpan(text: ' text', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.blue)),
    ],
  ),
)

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close