How to Disable Copy, Cut, Paste and Select All Toolbar on TextField Widget

In this example, we are going to show you the way to disable copy, cut, paste, and select all toolbar on TextField widget. You may need to disable these toolbar on your app, see the example below for more details:

Disable Copy, Cut, Paste, and Select Toolbar on TextField Widget:

TextField(
  toolbarOptions: ToolbarOptions(
    copy:false,
    paste: false,
    cut: false,
    selectAll: true
    //by default all are disabled 'false'
  ),
)

Full Code Example:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatelessWidget{

  @override
  Widget build(BuildContext context) {
    return  Scaffold(
          appBar: AppBar( 
             title: Text("Copy & Paste with Dart"),
             backgroundColor: Colors.indigoAccent,
          ),
          body: Container(
            alignment: Alignment.center,
            padding: EdgeInsets.all(20),
            child: Column(children: [
                
                TextField(
                  toolbarOptions: ToolbarOptions(
                    copy:false,
                    paste: false,
                    cut: false,
                    selectAll: true
                    //by default all are disabled 'false'
                  ),
                   decoration: InputDecoration( 
                      labelText: "Disabled Copy & Paste"
                   ),
                ),

                 TextField(
                   toolbarOptions: ToolbarOptions(
                    selectAll:false,
                    copy: true,
                    cut: true,
                    paste: true,
                  ),
                   decoration: InputDecoration( 
                      labelText: "Disabled Select All"
                   ),
                ),

            ],)
            
          )
       );
  }
}

Output Screenshot:

In this way, you can disable copy, paste, cut, select all toolbar on TextField widget in Flutter apps. 

No any Comments on this Article


Please Wait...