How to Make a Text Widget Selectable in Flutter

Sometimes you may want to make the Text content of your mobile selectable to use functionalities such as copy. In this Flutter tutorial, let’s check how to make a Text selectable in Flutter.

Making a text selectable is pretty easy in Flutter, you just need to use SelectableText widget. You can use SelectableText widget as given below.

SelectableText(
  'Hello! How are you?',
  textAlign: TextAlign.center,
  style: TextStyle(fontWeight: FontWeight.bold),
)

Following is the complete example of Flutter selectable text.

import 'package:flutter/material.dart';



class SelectableTextExample extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Tutorials',
      home: Main()
    );
  }
}

/// This is the stateless widget that the main application instantiates.
class Main extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Flutter Selectable Text Example'),
      ),
      body: Center(
        child: SelectableText(
  'Hello! Welcome to Flutterforyou.com. You will get useful Flutter tutorials here.',
  textAlign: TextAlign.center,
  style: TextStyle(fontWeight: FontWeight.bold,fontSize: 18,color: Colors.green),
)
        
        
      ),
    );
  }
}

And here’s the output of this Flutter tutorial.

selectable text flutter example

Thank you for reading!

Leave a Comment

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