How To Add Selectable Text Using Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 06-11-2020

The SelectableText widget displays a string of text with a single style. The string might break across multiple lines or might all be displayed on the same line depending on the layout constraints.Flutter SelectableText.You must be very familiar with text selection in web pages where you use mouse to select text in a page. Similarly you can make user to select some of the text displayed in your application using SelectableText widget.

How To Add Selectable Text Using Flutter Android App

Selectable Text 

When you display the text using SelectableText widget, user can select the part of it.Following is the quick code snippet of SelectableText widget. You can set style and alignment for the text.
The first argument to SelectableText is the text you would like to display with the capability to be selected by the user. we shall use SelectableText with some sample text ., 
When you long press on part of the text, piece of the text would be selected and you can use the seekers to change the start and end of your selection.



Complete Code For Selectable Text In Flutter 
main.dart

 

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
          appBar: AppBar(
            backgroundColor: Colors.indigo,
            title: Text('Selectable Text'),
          ),
          body: ListView(children: <Widget>[
            Container(
                padding: EdgeInsets.all(20),
                child: SelectableText(
                  'Lorem Ipsum is simply dummy text of the '
                      'printing and typesetting industry.'
                      ' Lorem Ipsum has been the industrys '
                      'standard dummy text ever since the 1500s,'
                      ' when an unknown printer took a galley of'
                      ' type and scrambled it to make a type specimen book.',
                  textAlign: TextAlign.center,
                  style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
                )),
          ])),
    );
  }
}

Related Post