secure_textfield 1.0.1 copy "secure_textfield: ^1.0.1" to clipboard
secure_textfield: ^1.0.1 copied to clipboard

A Flutter package that provides a secure text field widget blocking copy/paste functionality across iOS, Android, and web platforms.

Secure TextField #

CI Check Test Coverage codecov pub package

A Flutter package that provides a secure text field widget which blocks copy, paste, cut, and select all operations across iOS, Android, and web platforms.

Features #

Cross-platform support: Works on iOS, Android, and web browsers
Comprehensive blocking: Prevents copy, paste, cut, and select all operations
Keyboard shortcuts prevention: Blocks Ctrl+C/V/X/A and Cmd+C/V/X/A using Flutter's Shortcuts widget
Context menu blocking: Disables right-click and long-press context menus with custom contextMenuBuilder
Text selection disabled: Prevents text selection with enableInteractiveSelection: false
All TextField features: Supports all standard TextField properties and callbacks

Getting started #

Add the package to your pubspec.yaml:

dependencies:
  secure_textfield: ^1.0.0

Then run:

flutter pub get

Usage #

Import the package and use SecureTextField instead of the standard TextField:

import 'package:flutter/material.dart';
import 'package:secure_textfield/secure_textfield.dart';

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SecureTextField(
      decoration: InputDecoration(
        labelText: 'Secure Input',
        hintText: 'Copy/paste is blocked here',
        border: OutlineInputBorder(),
      ),
      onChanged: (value) {
        print('Text changed: $value');
      },
    );
  }
}

Password Field Example #

SecureTextField(
  obscureText: true,
  decoration: InputDecoration(
    labelText: 'Password',
    prefixIcon: Icon(Icons.lock),
    border: OutlineInputBorder(),
  ),
)

Multiline Example #

SecureTextField(
  maxLines: 4,
  decoration: InputDecoration(
    labelText: 'Comments',
    hintText: 'Enter your comments here...',
    border: OutlineInputBorder(),
    alignLabelWithHint: true,
  ),
)

With Controller #

final TextEditingController controller = TextEditingController();

SecureTextField(
  controller: controller,
  decoration: InputDecoration(
    labelText: 'Controlled Input',
    border: OutlineInputBorder(),
  ),
  onSubmitted: (value) {
    print('Submitted: $value');
  },
)

Supported Properties #

SecureTextField supports all the same properties as Flutter's standard TextField:

  • controller: TextEditingController for managing text
  • decoration: InputDecoration for styling
  • obscureText: Hide text input (for passwords)
  • maxLines: Number of lines (1 for single line, null for unlimited)
  • maxLength: Maximum character count
  • onChanged: Callback when text changes
  • onSubmitted: Callback when user submits
  • keyboardType: Type of keyboard to show
  • textInputAction: Action button on keyboard
  • style: Text styling
  • textAlign: Text alignment
  • enabled: Enable/disable the field
  • autofocus: Auto-focus on widget creation
  • readOnly: Make field read-only
  • focusNode: Custom focus management
  • And many more...

Platform-Specific Behavior #

iOS & macOS #

  • Blocks Cmd+C, Cmd+V, Cmd+X, Cmd+A keyboard shortcuts
  • Disables context menus through right-click/long-press
  • Prevents text selection (enableInteractiveSelection is false)

Android & Windows/Linux #

  • Blocks Ctrl+C, Ctrl+V, Ctrl+X, Ctrl+A keyboard shortcuts
  • Disables context menus through right-click/long-press
  • Prevents text selection (enableInteractiveSelection is false)

Web #

  • Blocks both Ctrl and Cmd keyboard shortcuts
  • Disables right-click context menu
  • Prevents browser's built-in copy/paste functionality

Implementation Details #

The package uses a unified approach across all platforms:

  • Shortcuts widget to intercept and block keyboard combinations
  • Listener widget to detect and block right-click mouse events
  • Custom contextMenuBuilder that returns an empty widget
  • enableInteractiveSelection: false to prevent text selection

Example App #

Check out the example app for a comprehensive demonstration of all features:

cd example
flutter run

Testing #

The package includes comprehensive tests covering:

  • Widget behavior and rendering
  • Platform-specific functionality
  • Keyboard shortcut blocking
  • All TextField property support
  • Edge cases and error scenarios

Run tests with:

flutter test

Test Coverage #

Generate and view test coverage:

# Generate coverage report
flutter test --coverage

# View coverage in browser (requires lcov)
genhtml coverage/lcov.info -o coverage/html
open coverage/html/index.html

Coverage reports are automatically generated and uploaded to Codecov on every PR and push to main.

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Commit Convention #

This project uses Conventional Commits for automated changelog generation and version bumping. Please format your commit messages as:

<type>[optional scope]: <description>

Examples:

  • feat: add new validation feature
  • fix: resolve input focus issue
  • docs: update README with new examples

See .github/CONVENTIONAL_COMMITS.md for detailed guidelines.

Release Process #

Releases are automated using Release Please:

  1. Commit changes using conventional commit format
  2. Push to main branch
  3. Release Please automatically creates a release PR with updated version and changelog
  4. When the release PR is merged, a new GitHub release is created
  5. The package can then be published to pub.flutter-io.cn (currently manual)

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Additional Information #

  • Issue Tracker: GitHub Issues
  • Documentation: Check the API documentation for detailed information about all available properties and methods
  • Changelog: See CHANGELOG.md for version history

Security Considerations #

This package provides UI-level protection against copy/paste operations. For sensitive data:

  1. Use additional server-side validation
  2. Implement proper data encryption
  3. Consider using secure storage solutions
  4. Be aware that determined users may still find ways to extract data

The package is designed to prevent casual copy/paste operations and improve user experience, but should not be relied upon as the sole security measure for highly sensitive data.

0
likes
160
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package that provides a secure text field widget blocking copy/paste functionality across iOS, Android, and web platforms.

Repository (GitHub)
View/report issues

Topics

#flutter #security #textfield #copy-paste #input-protection

Documentation

API reference

License

MIT (license)

Dependencies

flutter, universal_io

More

Packages that depend on secure_textfield