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
- User selects text in any Android app
- Android shows text selection menu
- User taps your app (e.g. "Ask AI")
- 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 π
- User selects text in any Android app
- Android shows the text selection menu
- User taps Ask AI
- Your app opens automatically
- Selected text is delivered to Flutter
Additional Information βΉοΈ
- This plugin works only on Android
- Requires Android API 23+
- Uses Androidβs official
ACTION_PROCESS_TEXTintent - The system text selection UI cannot be customized (Android limitation)
License π This package is licensed under the MIT License.