text_selection_intent 0.0.1 copy "text_selection_intent: ^0.0.1" to clipboard
text_selection_intent: ^0.0.1 copied to clipboard

PlatformAndroid

A Flutter plugin that allows your Android app to appear in the system text selection menu.

text_selection_intent #

A Flutter plugin that allows your Android app to appear in the system text selection menu and receive selected text using Android’s ACTION_PROCESS_TEXT intent.

This is the same mechanism used by apps like ChatGPT, Google Translate, and Dictionary.


✨ Features #

  • πŸ“± Appears in Android text selection menu
  • πŸ“ Receives selected text from any app
  • ⚑ Lightweight & fast
  • 🧩 Android-only (safe platform handling)
  • πŸš€ pub.dev compliant plugin architecture

πŸ“Έ How it works #

  1. User selects text in any Android app
  2. Android shows text selection menu
  3. User taps your app (e.g. "Ask AI")
  4. Selected text is delivered to Flutter

🧩 Platform Support #

Platform Support
Android βœ… Yes
iOS ❌ No
Web ❌ No
Desktop ❌ No

Installation #

Add this package to your project by running:

flutter pub add text_selection_intent

Or, manually add it to your pubspec.yaml file:

dependencies: text_selection_intent: latest_version

Android Setup βš™οΈ (Required) #

To make your app appear in the Android text selection menu, you need to add an intent-filter to your app’s MainActivity.

πŸ“‚ File location: android/app/src/main/AndroidManifest.xml

Add the following INSIDE <activity>

<activity
    android:name=".MainActivity"
    android:exported="true"
    android:launchMode="singleTop">

    <!-- App launcher -->
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    <!-- Text selection menu entry -->
    <intent-filter android:label="Ask AI">  // you can rename this
        <action android:name="android.intent.action.PROCESS_TEXT" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />
    </intent-filter>

</activity>

πŸ“Œ Important Notes

  • android:label β†’ Text shown in the selection menu
  • Must be added inside <activity>, not <application>
  • launchMode="singleTop" prevents multiple app instances
  • This step is mandatory

Usage πŸ“Œ

Import the package:

import 'package:text_selection_intent/text_selection_intent.dart';

How to Use πŸ› οΈ

Use the following code to start listening for selected text:

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

class TextSelectionExample extends StatefulWidget {
  @override
  State<TextSelectionExample> createState() =>
      _TextSelectionExampleState();
}

class _TextSelectionExampleState
    extends State<TextSelectionExample> {

  String selectedText = 'No text selected';

  @override
  void initState() {
    super.initState();

    TextSelectionIntent.listen((text) {
      setState(() {
        selectedText = text;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Text Selection Intent'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Text(
          selectedText,
          style: const TextStyle(fontSize: 16),
        ),
      ),
    );
  }
}

How It Works πŸ”

  1. User selects text in any Android app
  2. Android shows the text selection menu
  3. User taps Ask AI
  4. Your app opens automatically
  5. Selected text is delivered to Flutter

Additional Information ℹ️

  • This plugin works only on Android
  • Requires Android API 23+
  • Uses Android’s official ACTION_PROCESS_TEXT intent
  • The system text selection UI cannot be customized (Android limitation)

License πŸ“„ This package is licensed under the MIT License.

0
likes
160
points
46
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin that allows your Android app to appear in the system text selection menu.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on text_selection_intent

Packages that implement text_selection_intent