Open In App

Flutter – Disable Cut, Copy, Paste and Select All Options in TextFormField

Last Updated : 04 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Flutter is a UI toolkit developed and maintained by Google. It was released in May 2017 to the public. It is now one of the most popular cross-platform development frameworks among beginners and experienced application developers. It has a straightforward learning curve and uses the Dart programming language for developing the applications.

Every app uses TextFields in one place or another in their apps. In this article, we will see how to disable the native cut, copy, paste, and select all options when the user long presses on the text.

Approach

For the TextFormField widget in Flutter the enableInteractiveSelection property states whether those cut, copy, paste, and select all options are enabled or not. This property is set to true by default. To disable all those options, we can simply set the enableInteractiveSelection property to false. A sample video is given below to get an idea about what we are going to do in this article.

Syntax

TextFormField(
enableInteractiveSelection: false,
keyboardType: TextInputType.text,
)

Example Project

The below example shows how to disable Cut, Copy, Paste, and Select All options in TextFormField in Flutter.

Dart




import 'package:flutter/material.dart';
  
void main() {
    runApp(const MyApp());
}
  
class MyApp extends StatelessWidget {
    const MyApp({super.key});
  
    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            title: 'GFG - Disable TextFormField Options',
            theme: ThemeData(primarySwatch: Colors.green),
            debugShowCheckedModeBanner: false,
            home: const Home(),
        );
    }
}
  
class Home extends StatelessWidget {
    const Home({super.key});
  
    @override
    Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
                title: const Text("Disable TextFormField Options"),
            ),
            body: Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                        TextFormField(
                            decoration: const InputDecoration(
                                border: OutlineInputBorder(),
                                labelText: "Default TextField",
                            ),
                            keyboardType: TextInputType.text,
                        ),
                        const SizedBox(
                            height: 50,
                        ),
                        TextFormField(
                            enableInteractiveSelection: false,
                            decoration: const InputDecoration(
                                border: OutlineInputBorder(),
                                labelText: "Options Disabled TextField",
                            ),
                            keyboardType: TextInputType.text,
                        )
                    ],
                ),
            ),
        );
    }
}


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads