Open In App

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

Last Updated : 18 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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 the 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.

Syntax :

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

Example:

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());
}

// Main application widget
class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'GFG - Disable TextFormField Options',
      debugShowCheckedModeBanner: false,
      home: Home(),
    );
  }
}

// Home screen widget
class Home extends StatelessWidget {
  const Home({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Disable TextFormField Options"),
        backgroundColor: Colors.green,
        foregroundColor: Colors.white,
      ),
      body: Padding(
        padding: const EdgeInsets.symmetric(horizontal: 20),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            
            // Default TextFormField with no restrictions
            TextFormField(
              decoration: const InputDecoration(
                border: OutlineInputBorder(),
                labelText: "Default TextField",
              ),
              keyboardType: TextInputType.text,
            ),
            const SizedBox(
              height: 50,
            ),
            
            // TextFormField with interactive selection disabled
            TextFormField(
              
              // Disabling text selection options
              enableInteractiveSelection: false,
              decoration: const InputDecoration(
                border: OutlineInputBorder(),
                labelText: "Options Disabled TextField",
              ),
              keyboardType: TextInputType.text,
            )
          ],
        ),
      ),
    );
  }
}


Output:



Next Article
Article Tags :

Similar Reads