Coder Social home page Coder Social logo

coder-with-a-bushido / action_process_text-flutter Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 7.0 116 KB

A Flutter plugin for ACTION_PROCESS_TEXT implementation in android.

License: MIT License

Kotlin 30.85% Dart 47.24% Ruby 16.52% Swift 4.93% Objective-C 0.46%

action_process_text-flutter's Introduction

ACTION_PROCESS_TEXT Flutter

A flutter plugin for ACTION_PROCESS_TEXT implementation in android.

What is it used for?

It can be used when you want your users to use a shortcut for opening your app when selecting text anywhere in the android environment.

Constraints

1. It works only for android.

2. It can only be used inside a Stateful widget.

3. Use setState() after updating the value from the action.

Include in your project

dependencies:
  action_process_text: <latest version>

Run pub get and get packages.

Add this to AndroidManifest.xml in the android\app\src\main\ folder.

  <activity android:name="com.example.action_process_text.ActionProcessTextPlugin"
            android:label="Action_Text" android:theme="@style/LaunchTheme">
            <intent-filter>
                <action android:name="android.intent.action.PROCESS_TEXT" />
                <data android:mimeType="text/plain"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
   </activity>

Change the android:label from Action_Text to the action text that you want to display.

Then import the package to use it.

import 'package:action_process_text/action_process_text.dart';

Usage

Use the constructor of the widget to initialize the action_process_text. ActionProcessText.getInputText is used to get the selected text from the android action.

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  _MainPageState() {
    initActionProcessText();
  }

  Future<void> initActionProcessText() async {
    inputText = await ActionProcessText.getInputText;
    setState(() {});
  }

  String inputText = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold();
  }
  }

If you want to check whether the call was made from the native side, you can use the ActionProcessText.calledFromNative . This enables one to navigate to a different screen than usual if needed, by initiating the channel at the start and check if the value is true. If true, the input text will be available. When it's false, the app is opened not by the action_process_text intend, but by the user as in usual cases.

Bugs/Requests

If you encounter any problems feel free to open an issue. Pull request are also welcome.

action_process_text-flutter's People

Contributors

coder-with-a-bushido avatar mxdscientist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

action_process_text-flutter's Issues

I have receive empty string in the app.

When I tested the plug-in on android simulator. I am selecting test and click the app name on the context menu. I have received empty string in the app.

I have added the below code to my main activity.

<intent-filter>
      <action android:name="android.intent.action.PROCESS_TEXT" />
      <data android:mimeType="text/plain"/>
      <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>

So I didn't create a new activity for the plugin like that.

 <activity android:name="com.example.action_process_text.ActionProcessTextPlugin" android:label="Action_Text" android:theme="@style/LaunchTheme">
...
</activity>

Is that can be a problem?

I didn't add the activity because I need to start the activity from .MainActivity

issue with firebase plugin

I am getting this error when app open via action_process else its work perfect,

`[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core)
E/flutter ( 3613): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157:7)
E/flutter ( 3613): <asynchronous suspension>
E/flutter ( 3613): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
E/flutter ( 3613): #2      MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:345:41)
E/flutter ( 3613): #3      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30:36)
E/flutter ( 3613): #4      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:75:13)
E/flutter ( 3613): #5      Firebase.initializeApp (package:firebase_core/src/firebase.dart:44:25)
E/flutter ( 3613): #6      main (package:revwe/main.dart:19:18)
E/flutter ( 3613): #7      _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:231:25)
E/flutter ( 3613): #8      _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 3613): #9      _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 3613): #10     _runZoned (dart:async/zone.dart:1630:10)
E/flutter ( 3613): #11     runZonedGuarded (dart:async/zone.dart:1618:12)
E/flutter ( 3613): #12     _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:223:5)
E/flutter ( 3613): #13     _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:301:19)
E/flutter ( 3613): #14     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter ( 3613): `
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.6, on macOS 11.2.1 20D74 darwin-x64, locale en-CA)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 12.4)
[✓] Android Studio (version 4.1)
[✓] Connected device (1 available)
```
`

in AndroidManifest.xml added this lines
`<activity android:name="com.example.action_process_text.ActionProcessTextPlugin"
            android:label="My search" android:theme="@style/LaunchTheme">
            <intent-filter>
                <action android:name="android.intent.action.PROCESS_TEXT" />
                <data android:mimeType="text/plain"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>`

Multi-page support

The plugin can only be used for apps with the text-getting page as the initial page. So, support for multi-page apps is needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.