diff --git a/packages/mediapipe-task-text/mediapipe_task_text/.gitignore b/packages/mediapipe-task-text/mediapipe_task_text/.gitignore new file mode 100644 index 00000000..96486fd9 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/packages/mediapipe-task-text/mediapipe_task_text/.metadata b/packages/mediapipe-task-text/mediapipe_task_text/.metadata new file mode 100644 index 00000000..20209518 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/.metadata @@ -0,0 +1,30 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: 1ca183d55b24c0813b477478743df67ccca460a4 + channel: master + +project_type: plugin + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + base_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + - platform: android + create_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + base_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/mediapipe-task-text/mediapipe_task_text/CHANGELOG.md b/packages/mediapipe-task-text/mediapipe_task_text/CHANGELOG.md new file mode 100644 index 00000000..41cc7d81 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* TODO: Describe initial release. diff --git a/packages/mediapipe-task-text/LICENSE b/packages/mediapipe-task-text/mediapipe_task_text/LICENSE similarity index 100% rename from packages/mediapipe-task-text/LICENSE rename to packages/mediapipe-task-text/mediapipe_task_text/LICENSE diff --git a/packages/mediapipe-task-text/README.md b/packages/mediapipe-task-text/mediapipe_task_text/README.md similarity index 100% rename from packages/mediapipe-task-text/README.md rename to packages/mediapipe-task-text/mediapipe_task_text/README.md diff --git a/packages/mediapipe-task-text/mediapipe_task_text/analysis_options.yaml b/packages/mediapipe-task-text/mediapipe_task_text/analysis_options.yaml new file mode 100644 index 00000000..a5744c1c --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/.gitignore b/packages/mediapipe-task-text/mediapipe_task_text/example/.gitignore new file mode 100644 index 00000000..24476c5d --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/.gitignore @@ -0,0 +1,44 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/README.md b/packages/mediapipe-task-text/mediapipe_task_text/example/README.md new file mode 100644 index 00000000..c66e5be2 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/README.md @@ -0,0 +1,16 @@ +# mediapipe_task_text_example + +Demonstrates how to use the mediapipe_task_text plugin. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/analysis_options.yaml b/packages/mediapipe-task-text/mediapipe_task_text/example/analysis_options.yaml new file mode 100644 index 00000000..61b6c4de --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/.gitignore b/packages/mediapipe-task-text/mediapipe_task_text/example/android/.gitignore new file mode 100644 index 00000000..6f568019 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/.gitignore @@ -0,0 +1,13 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties +**/*.keystore +**/*.jks diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/build.gradle b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/build.gradle new file mode 100644 index 00000000..9f5cd4b9 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/build.gradle @@ -0,0 +1,67 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +android { + namespace "com.google.mediapipe_task_text_example" + compileSdkVersion flutter.compileSdkVersion + ndkVersion flutter.ndkVersion + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "com.google.mediapipe_task_text_example" + // You can update the following values to match your application needs. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. + minSdkVersion flutter.minSdkVersion + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies {} diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/debug/AndroidManifest.xml b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 00000000..399f6981 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/AndroidManifest.xml b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..88cc5b72 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/kotlin/com/google/mediapipe_task_text_example/MainActivity.kt b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/kotlin/com/google/mediapipe_task_text_example/MainActivity.kt new file mode 100644 index 00000000..807211f5 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/kotlin/com/google/mediapipe_task_text_example/MainActivity.kt @@ -0,0 +1,6 @@ +package com.google.mediapipe_task_text_example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/drawable-v21/launch_background.xml b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 00000000..f74085f3 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/drawable/launch_background.xml b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 00000000..304732f8 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..db77bb4b Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..17987b79 Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..09d43914 Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..d5f1c8d3 Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..4d6372ee Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/values-night/styles.xml b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 00000000..06952be7 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/values/styles.xml b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/values/styles.xml new file mode 100644 index 00000000..cb1ef880 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/profile/AndroidManifest.xml b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 00000000..399f6981 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/build.gradle b/packages/mediapipe-task-text/mediapipe_task_text/example/android/build.gradle new file mode 100644 index 00000000..f7eb7f63 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/build.gradle @@ -0,0 +1,31 @@ +buildscript { + ext.kotlin_version = '1.7.10' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.3.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') +} + +tasks.register("clean", Delete) { + delete rootProject.buildDir +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/gradle.properties b/packages/mediapipe-task-text/mediapipe_task_text/example/android/gradle.properties new file mode 100644 index 00000000..94adc3a3 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/mediapipe-task-text/mediapipe_task_text/example/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..3c472b99 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/android/settings.gradle b/packages/mediapipe-task-text/mediapipe_task_text/example/android/settings.gradle new file mode 100644 index 00000000..55c4ca8b --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/android/settings.gradle @@ -0,0 +1,20 @@ +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + } + settings.ext.flutterSdkPath = flutterSdkPath() + + includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle") + + plugins { + id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false + } +} + +include ":app" + +apply from: "${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/integration_test/plugin_integration_test.dart b/packages/mediapipe-task-text/mediapipe_task_text/example/integration_test/plugin_integration_test.dart new file mode 100644 index 00000000..764d2157 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/integration_test/plugin_integration_test.dart @@ -0,0 +1,24 @@ +// This is a basic Flutter integration test. +// +// Since integration tests run in a full Flutter application, they can interact +// with the host side of a plugin implementation, unlike Dart unit tests. +// +// For more information about Flutter integration tests, please see +// https://docs.flutter.dev/cookbook/testing/integration/introduction + +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +import 'package:mediapipe_task_text/mediapipe_task_text.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('getPlatformVersion test', (WidgetTester tester) async { + final MediaPipeTaskText plugin = MediaPipeTaskText('fake'); + // final String? version = await plugin.getPlatformVersion(); + // The version string depends on the host platform running the test, so + // just assert that some non-empty string is returned. + // expect(version?.isNotEmpty, true); + }); +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/lib/main.dart b/packages/mediapipe-task-text/mediapipe_task_text/example/lib/main.dart new file mode 100644 index 00000000..131d719b --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/lib/main.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; +import 'dart:async'; + +import 'package:mediapipe_task_text/mediapipe_task_text.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatefulWidget { + const MyApp({super.key}); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + // TODO: probably need to pull this from pubspec.yaml + final _mediapipeTaskTextPlugin = MediaPipeTaskText('fake'); + + @override + void initState() { + super.initState(); + initPlatformState(); + } + + // Platform messages are asynchronous, so we initialize in an async method. + Future initPlatformState() async { + // Platform messages may fail, so we use a try/catch PlatformException. + // We also handle the message potentially returning null. + + // If the widget was removed from the tree while the asynchronous platform + // message was in flight, we want to discard the reply rather than calling + // setState to update our non-existent appearance. + if (!mounted) return; + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('Plugin example app'), + ), + body: const Center( + // child: Text('Running on: $_platformVersion\n'), + ), + ), + ); + } +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/pubspec.yaml b/packages/mediapipe-task-text/mediapipe_task_text/example/pubspec.yaml new file mode 100644 index 00000000..a5aec7c4 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/pubspec.yaml @@ -0,0 +1,85 @@ +name: mediapipe_task_text_example +description: Demonstrates how to use the mediapipe_task_text plugin. +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +environment: + sdk: '>=3.1.0-113.0.dev <4.0.0' + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + mediapipe_task_text: + # When depending on this package from a real application you should use: + # mediapipe_task_text: ^x.y.z + # See https://dart.dev/tools/pub/dependencies#version-constraints + # The example app is bundled with the plugin so we use a path dependency on + # the parent directory to use the current plugin's version. + path: ../ + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + +dev_dependencies: + integration_test: + sdk: flutter + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^2.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/mediapipe-task-text/mediapipe_task_text/example/test/widget_test.dart b/packages/mediapipe-task-text/mediapipe_task_text/example/test/widget_test.dart new file mode 100644 index 00000000..e20bdb39 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/example/test/widget_test.dart @@ -0,0 +1,27 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:mediapipe_task_text_example/main.dart'; + +void main() { + testWidgets('Verify Platform version', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that platform version is retrieved. + expect( + find.byWidgetPredicate( + (Widget widget) => widget is Text && + widget.data!.startsWith('Running on:'), + ), + findsOneWidget, + ); + }); +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text/lib/mediapipe_task_text.dart b/packages/mediapipe-task-text/mediapipe_task_text/lib/mediapipe_task_text.dart new file mode 100644 index 00000000..48479f4b --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/lib/mediapipe_task_text.dart @@ -0,0 +1,14 @@ +import 'package:mediapipe_task_text_platform_interface/mediapipe_task_text_platform_interface.dart'; + +class MediaPipeTaskText { + MediaPipeTaskText(this.modelPath); + + String modelPath; + + Future initClassifier() { + return MediaPipeTaskTextPlatform.instance.initClassifier(modelPath); + } + + Future classify(String value) => + MediaPipeTaskTextPlatform.instance.classify(value); +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text/pubspec.yaml b/packages/mediapipe-task-text/mediapipe_task_text/pubspec.yaml new file mode 100644 index 00000000..eb1ca6ee --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/pubspec.yaml @@ -0,0 +1,64 @@ +name: mediapipe_task_text +description: A Flutter plugin for using MediaPipe's text-based Tasks. +version: 0.0.1 +repository: https://github.com/google/flutter-mediapipe/tree/main/packages/mediapipe-task-text/mediapipe_task_text + +# TODO: Remove this when ready to upload to pub.dev. +publish_to: none + +environment: + sdk: '>=3.0.0 <4.0.0' + flutter: ">=3.10.0" + +dependencies: + mediapipe_task_text_android: + # TODO: Change this to pin an actual version when the package is ready to be uploaded to pub.dev. + path: ../mediapipe_task_text_android + mediapipe_task_text_platform_interface: + # TODO: Change this to pin an actual version when the package is ready to be uploaded to pub.dev. + path: ../mediapipe_task_text_platform_interface + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 + +flutter: + plugin: + platforms: + android: + default_package: mediapipe_task_text_android + + # To add assets to your plugin package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # To add custom fonts to your plugin package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/mediapipe-task-text/mediapipe_task_text/test/mediapipe_task_text_method_channel_test.dart b/packages/mediapipe-task-text/mediapipe_task_text/test/mediapipe_task_text_method_channel_test.dart new file mode 100644 index 00000000..3bd7bfd1 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/test/mediapipe_task_text_method_channel_test.dart @@ -0,0 +1,31 @@ +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mediapipe_task_text_platform_interface/mediapipe_task_text_platform_interface.dart'; + +// TODO: Move to platform_interface + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + MethodChannelMediaPipeTaskText platform = MethodChannelMediaPipeTaskText(); + const MethodChannel channel = MethodChannel('mediapipe_task_text'); + + setUp(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler( + channel, + (MethodCall methodCall) async { + return '42'; + }, + ); + }); + + tearDown(() { + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(channel, null); + }); + + test('getPlatformVersion', () async { + // expect(await platform.getPlatformVersion(), '42'); + }); +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text/test/mediapipe_task_text_test.dart b/packages/mediapipe-task-text/mediapipe_task_text/test/mediapipe_task_text_test.dart new file mode 100644 index 00000000..5241931d --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text/test/mediapipe_task_text_test.dart @@ -0,0 +1,29 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:mediapipe_task_text/mediapipe_task_text.dart'; +import 'package:mediapipe_task_text_platform_interface/mediapipe_task_text_platform_interface.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +class MockMediaPipeTaskTextPlatform + with MockPlatformInterfaceMixin + implements MediaPipeTaskTextPlatform { + @override + Future classify(String value) { + // TODO: implement classify + throw UnimplementedError(); + } + + @override + Future initClassifier(String modelPath) { + // TODO: implement initClassifier + throw UnimplementedError(); + } +} + +void main() { + final MediaPipeTaskTextPlatform initialPlatform = + MediaPipeTaskTextPlatform.instance; + + test('$MethodChannelMediaPipeTaskText is the default instance', () { + expect(initialPlatform, isInstanceOf()); + }); +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/.gitignore b/packages/mediapipe-task-text/mediapipe_task_text_android/.gitignore new file mode 100644 index 00000000..96486fd9 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/.metadata b/packages/mediapipe-task-text/mediapipe_task_text_android/.metadata new file mode 100644 index 00000000..6cab8543 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 1ca183d55b24c0813b477478743df67ccca460a4 + channel: master + +project_type: package diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/CHANGELOG.md b/packages/mediapipe-task-text/mediapipe_task_text_android/CHANGELOG.md new file mode 100644 index 00000000..41cc7d81 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* TODO: Describe initial release. diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/LICENSE b/packages/mediapipe-task-text/mediapipe_task_text_android/LICENSE new file mode 100644 index 00000000..ba75c69f --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/LICENSE @@ -0,0 +1 @@ +TODO: Add your license here. diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/README.md b/packages/mediapipe-task-text/mediapipe_task_text_android/README.md new file mode 100644 index 00000000..02fe8eca --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/analysis_options.yaml b/packages/mediapipe-task-text/mediapipe_task_text_android/analysis_options.yaml new file mode 100644 index 00000000..a5744c1c --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/android/.gitignore b/packages/mediapipe-task-text/mediapipe_task_text_android/android/.gitignore new file mode 100644 index 00000000..161bdcda --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/android/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.cxx diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/android/.vscode/settings.json b/packages/mediapipe-task-text/mediapipe_task_text_android/android/.vscode/settings.json new file mode 100644 index 00000000..c5f3f6b9 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/android/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/android/build.gradle b/packages/mediapipe-task-text/mediapipe_task_text_android/android/build.gradle new file mode 100644 index 00000000..49ee8dee --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/android/build.gradle @@ -0,0 +1,70 @@ +group 'com.google.mediapipe_task_text' +version '1.0-SNAPSHOT' + +buildscript { + ext.kotlin_version = '1.7.10' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.3.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + +android { + if (project.android.hasProperty("namespace")) { + namespace 'com.google.mediapipe_task_text' + } + + compileSdkVersion 31 + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + test.java.srcDirs += 'src/test/kotlin' + } + + defaultConfig { + minSdkVersion 24 + } + + dependencies { + implementation 'com.google.mediapipe:tasks-text:0.1.0-alpha-5' + implementation 'androidx.annotation:annotation:1.5.0' + testImplementation 'org.jetbrains.kotlin:kotlin-test' + testImplementation 'org.mockito:mockito-core:5.0.0' + } + + testOptions { + unitTests.all { + useJUnitPlatform() + + testLogging { + events "passed", "skipped", "failed", "standardOut", "standardError" + outputs.upToDateWhen {false} + showStandardStreams = true + } + } + } +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/android/gradle/wrapper/gradle-wrapper.properties b/packages/mediapipe-task-text/mediapipe_task_text_android/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..e750102e --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/android/settings.gradle b/packages/mediapipe-task-text/mediapipe_task_text_android/android/settings.gradle new file mode 100644 index 00000000..7d123d68 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'mediapipe_task_text_android' diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/main/AndroidManifest.xml b/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/main/AndroidManifest.xml new file mode 100644 index 00000000..974a2a6f --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/main/kotlin/com/google/mediapipe_task_text/MediapipeTaskTextPlugin.kt b/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/main/kotlin/com/google/mediapipe_task_text/MediapipeTaskTextPlugin.kt new file mode 100644 index 00000000..d88e0e23 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/main/kotlin/com/google/mediapipe_task_text/MediapipeTaskTextPlugin.kt @@ -0,0 +1,57 @@ +package com.google.mediapipe_task_text + +import androidx.annotation.NonNull + +import android.content.Context +import android.os.SystemClock +import android.util.Log +import io.flutter.embedding.engine.plugins.FlutterPlugin +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import io.flutter.plugin.common.MethodChannel.MethodCallHandler +import io.flutter.plugin.common.MethodChannel.Result +import com.google.mediapipe.examples.textclassifier.TextClassifierHelper + + +/** MediaPipeTaskTextPlugin */ +class MediaPipeTaskTextPlugin: FlutterPlugin, MethodCallHandler { + /// The MethodChannel that will the communication between Flutter and native Android + /// + /// This local reference serves to register the plugin with the Flutter Engine and unregister it + /// when the Flutter Engine is detached from the Activity + private lateinit var channel : MethodChannel + private lateinit var context: Context + private lateinit var classifierHelper: TextClassifierHelper + + fun registerWith( + @NonNull registrar: io.flutter.plugin.common.PluginRegistry.Registrar + ) { + val plugin = MediaPipeTaskTextPlugin(); + } + + override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { + channel = MethodChannel(flutterPluginBinding.binaryMessenger, "mediapipe_task_text") + channel.setMethodCallHandler(this) + context = flutterPluginBinding.applicationContext + } + + override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) { + if (call.method == "initClassifier") { + classifierHelper = TextClassifierHelper( + currentModel = call.argument("modelPath")!!, + context = context, + ) + } else if (call.method == "classify") { + // a string (I think) + val results = classifierHelper.classify(call.argument("text") ?: "") + + result.success(results) + } else { + result.notImplemented() + } + } + + override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { + channel.setMethodCallHandler(null) + } +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/main/kotlin/com/google/mediapipe_task_text/TextClassifierHelper.kt b/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/main/kotlin/com/google/mediapipe_task_text/TextClassifierHelper.kt new file mode 100644 index 00000000..3fbb95b3 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/main/kotlin/com/google/mediapipe_task_text/TextClassifierHelper.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2022 The TensorFlow Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.mediapipe.examples.textclassifier + +import android.content.Context +import android.os.SystemClock +import android.util.Log +import com.google.mediapipe.tasks.core.BaseOptions +import com.google.mediapipe.tasks.text.textclassifier.TextClassifier +import com.google.mediapipe.tasks.text.textclassifier.TextClassifierResult +import java.util.concurrent.ScheduledThreadPoolExecutor + +class TextClassifierHelper( + var currentModel: String = WORD_VEC, + val context: Context, +) { + private lateinit var textClassifier: TextClassifier + private lateinit var executor: ScheduledThreadPoolExecutor + + init { + initClassifier() + } + + fun initClassifier() { + val baseOptionsBuilder = BaseOptions.builder() + .setModelAssetPath(currentModel) + + try { + val baseOptions = baseOptionsBuilder.build() + val optionsBuilder = TextClassifier.TextClassifierOptions.builder() + .setBaseOptions(baseOptions) + val options = optionsBuilder.build() + textClassifier = TextClassifier.createFromOptions(context, options) + } catch (e: IllegalStateException) { + Log.e( + TAG, "Text classifier failed to load the task with error: " + e + .message + ) + } + } + + // Run text classification using MediaPipe Text Classifier API + fun classify(text: String): String { + val results = textClassifier.classify(text) + val item = results.classificationResult().classifications()[0].categories()[0] + // TODO: MARSHAL `results`! + return item.categoryName() + " " + item.score(); + // return results + } + + companion object { + const val TAG = "TextClassifierHelper" + + const val WORD_VEC = "wordvec.tflite" + const val MOBILEBERT = "mobilebert.tflite" + } +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/test/kotlin/com/google/mediapipe_task_text/MediapipeTaskTextPluginTest.kt b/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/test/kotlin/com/google/mediapipe_task_text/MediapipeTaskTextPluginTest.kt new file mode 100644 index 00000000..c978e5fc --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/android/src/test/kotlin/com/google/mediapipe_task_text/MediapipeTaskTextPluginTest.kt @@ -0,0 +1,27 @@ +package com.google.mediapipe_task_text + +import io.flutter.plugin.common.MethodCall +import io.flutter.plugin.common.MethodChannel +import kotlin.test.Test +import org.mockito.Mockito + +/* + * This demonstrates a simple unit test of the Kotlin portion of this plugin's implementation. + * + * Once you have built the plugin's example app, you can run these tests from the command + * line by running `./gradlew testDebugUnitTest` in the `example/android/` directory, or + * you can run them directly from IDEs that support JUnit such as Android Studio. + */ + +internal class MediaPipeTaskTextPluginTest { + @Test + fun onMethodCall_getPlatformVersion_returnsExpectedValue() { + val plugin = MediaPipeTaskTextPlugin() + + val call = MethodCall("getPlatformVersion", null) + val mockResult: MethodChannel.Result = Mockito.mock(MethodChannel.Result::class.java) + plugin.onMethodCall(call, mockResult) + + Mockito.verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE) + } +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/.gitignore b/packages/mediapipe-task-text/mediapipe_task_text_android/example/.gitignore new file mode 100644 index 00000000..24476c5d --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/.gitignore @@ -0,0 +1,44 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies +.packages +.pub-cache/ +.pub/ +/build/ + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json + +# Android Studio will place build artifacts here +/android/app/debug +/android/app/profile +/android/app/release diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/.metadata b/packages/mediapipe-task-text/mediapipe_task_text_android/example/.metadata new file mode 100644 index 00000000..4372149d --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/.metadata @@ -0,0 +1,45 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: 1ca183d55b24c0813b477478743df67ccca460a4 + channel: master + +project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + base_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + - platform: android + create_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + base_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + - platform: ios + create_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + base_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + - platform: linux + create_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + base_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + - platform: macos + create_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + base_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + - platform: web + create_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + base_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + - platform: windows + create_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + base_revision: 1ca183d55b24c0813b477478743df67ccca460a4 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/README.md b/packages/mediapipe-task-text/mediapipe_task_text_android/example/README.md new file mode 100644 index 00000000..2b3fce4c --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/README.md @@ -0,0 +1,16 @@ +# example + +A new Flutter project. + +## Getting Started + +This project is a starting point for a Flutter application. + +A few resources to get you started if this is your first Flutter project: + +- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab) +- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook) + +For help getting started with Flutter development, view the +[online documentation](https://docs.flutter.dev/), which offers tutorials, +samples, guidance on mobile development, and a full API reference. diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/analysis_options.yaml b/packages/mediapipe-task-text/mediapipe_task_text_android/example/analysis_options.yaml new file mode 100644 index 00000000..61b6c4de --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/.gitignore b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/.gitignore new file mode 100644 index 00000000..6f568019 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/.gitignore @@ -0,0 +1,13 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java + +# Remember to never publicly share your keystore. +# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +key.properties +**/*.keystore +**/*.jks diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/build.gradle b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/build.gradle new file mode 100644 index 00000000..c5e6dd9f --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/build.gradle @@ -0,0 +1,67 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + +def localProperties = new Properties() +def localPropertiesFile = rootProject.file('local.properties') +if (localPropertiesFile.exists()) { + localPropertiesFile.withReader('UTF-8') { reader -> + localProperties.load(reader) + } +} + +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') +if (flutterVersionCode == null) { + flutterVersionCode = '1' +} + +def flutterVersionName = localProperties.getProperty('flutter.versionName') +if (flutterVersionName == null) { + flutterVersionName = '1.0' +} + +android { + namespace "com.example.example" + compileSdkVersion flutter.compileSdkVersion + ndkVersion flutter.ndkVersion + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = '1.8' + } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + + defaultConfig { + // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). + applicationId "com.example.example" + // You can update the following values to match your application needs. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. + minSdkVersion 24 + targetSdkVersion flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName + } + + buildTypes { + release { + // TODO: Add your own signing config for the release build. + // Signing with the debug keys for now, so `flutter run --release` works. + signingConfig signingConfigs.debug + } + } +} + +flutter { + source '../..' +} + +dependencies {} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/debug/AndroidManifest.xml b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 00000000..399f6981 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/AndroidManifest.xml b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..19b862ec --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/assets b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/assets new file mode 120000 index 00000000..2b56518e --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/assets @@ -0,0 +1 @@ +../../../../assets \ No newline at end of file diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt new file mode 100644 index 00000000..e793a000 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt @@ -0,0 +1,6 @@ +package com.example.example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() { +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/drawable-v21/launch_background.xml b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 00000000..f74085f3 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/drawable/launch_background.xml b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 00000000..304732f8 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 00000000..db77bb4b Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 00000000..17987b79 Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 00000000..09d43914 Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..d5f1c8d3 Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 00000000..4d6372ee Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/values-night/styles.xml b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 00000000..06952be7 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/values/styles.xml b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/values/styles.xml new file mode 100644 index 00000000..cb1ef880 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/profile/AndroidManifest.xml b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 00000000..399f6981 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/build.gradle b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/build.gradle new file mode 100644 index 00000000..f7eb7f63 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/build.gradle @@ -0,0 +1,31 @@ +buildscript { + ext.kotlin_version = '1.7.10' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.3.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') +} + +tasks.register("clean", Delete) { + delete rootProject.buildDir +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/gradle.properties b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/gradle.properties new file mode 100644 index 00000000..94adc3a3 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..3c472b99 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/settings.gradle b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/settings.gradle new file mode 100644 index 00000000..55c4ca8b --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/android/settings.gradle @@ -0,0 +1,20 @@ +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + } + settings.ext.flutterSdkPath = flutterSdkPath() + + includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle") + + plugins { + id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false + } +} + +include ":app" + +apply from: "${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/assets/model.tflite b/packages/mediapipe-task-text/mediapipe_task_text_android/example/assets/model.tflite new file mode 100644 index 00000000..97a32da4 Binary files /dev/null and b/packages/mediapipe-task-text/mediapipe_task_text_android/example/assets/model.tflite differ diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/lib/main.dart b/packages/mediapipe-task-text/mediapipe_task_text_android/example/lib/main.dart new file mode 100644 index 00000000..b1227e56 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/lib/main.dart @@ -0,0 +1,79 @@ +import 'package:flutter/material.dart'; +import 'package:mediapipe_task_text/mediapipe_task_text.dart'; + +void main() { + runApp(const MyApp()); +} + +class MyApp extends StatefulWidget { + const MyApp({super.key}); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + String? classification; + String? lastClassified; + final TextEditingController _controller = TextEditingController(); + final _mediaPipeTaskTextPlugin = MediaPipeTaskText('model.tflite'); + + @override + void initState() { + _mediaPipeTaskTextPlugin.initClassifier(); + super.initState(); + } + + Future classify() async { + setState(() => lastClassified = _controller.text); + final result = await _mediaPipeTaskTextPlugin.classify(_controller.text); + setState(() => classification = result?.value); + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Demo', + theme: ThemeData( + colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + useMaterial3: true, + ), + home: SafeArea( + child: Scaffold( + body: Center( + child: Stack( + children: [ + Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + lastClassified == null + ? const Text('Awaiting first classification...') + : Text('Running on "$lastClassified"'), + classification == null + ? Container() + : Text('Result: $classification'), + ], + ), + ), + Column( + children: [ + TextField(controller: _controller), + MaterialButton( + onPressed: classify, + color: Colors.blue, + child: const Text( + 'Classify', + style: TextStyle(color: Colors.white), + ), + ), + ], + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/pubspec.yaml b/packages/mediapipe-task-text/mediapipe_task_text_android/example/pubspec.yaml new file mode 100644 index 00000000..5d4eba9c --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/pubspec.yaml @@ -0,0 +1,93 @@ +name: example +description: A new Flutter project. +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: "none" # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +# In Windows, build-name is used as the major, minor, and patch parts +# of the product and file versions while build-number is used as the build suffix. +version: 1.0.0+1 + +environment: + sdk: ">=3.0.0 <4.0.0" + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + mediapipe_task_text: + path: ../../mediapipe_task_text + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^2.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + assets: + - assets/model.tflite + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/example/test/widget_test.dart b/packages/mediapipe-task-text/mediapipe_task_text_android/example/test/widget_test.dart new file mode 100644 index 00000000..092d222f --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/example/test/widget_test.dart @@ -0,0 +1,30 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:example/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(const MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/lib/mediapipe_task_text_android.dart b/packages/mediapipe-task-text/mediapipe_task_text_android/lib/mediapipe_task_text_android.dart new file mode 100644 index 00000000..f87e0bba --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/lib/mediapipe_task_text_android.dart @@ -0,0 +1,37 @@ +library mediapipe_task_text_android; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; +import 'package:mediapipe_task_text_platform_interface/mediapipe_task_text_platform_interface.dart'; + +class AndroidMediapipeTaskTextPlatform extends MediaPipeTaskTextPlatform { + AndroidMediapipeTaskTextPlatform(); + + static void registerWith() { + print('hey oh'); + MediaPipeTaskTextPlatform.instance = AndroidMediapipeTaskTextPlatform(); + } + + @visibleForTesting + final methodChannel = const MethodChannel('mediapipe_task_text'); + + @override + Future initClassifier(String modelPath) async { + await methodChannel.invokeMethod('initClassifier', { + 'modelPath': modelPath, + }); + } + + @override + Future classify(String value) async { + final serializedClassificationResult = + await methodChannel.invokeMethod('classify', { + 'text': value, + }); + if (serializedClassificationResult != null) { + return ClassificationResult.fromJson( + {'value': serializedClassificationResult}); + } + return null; + } +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/pubspec.yaml b/packages/mediapipe-task-text/mediapipe_task_text_android/pubspec.yaml new file mode 100644 index 00000000..bab80b5f --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/pubspec.yaml @@ -0,0 +1,30 @@ +name: mediapipe_task_text_android +description: A new Flutter package project. +version: 0.0.1 +publish_to: none +repository: https://github.com/google/flutter-mediapipe/tree/main/packages/mediapipe-task-text/mediapipe_task_text_android + +environment: + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" + +flutter: + plugin: + implements: mediapipe_task_text + platforms: + android: + package: com.google.mediapipe_task_text + pluginClass: MediaPipeTaskTextPlugin + dartPluginClass: AndroidMediapipeTaskTextPlatform + +dependencies: + mediapipe_task_text_platform_interface: + # TODO: Change this to pin an actual version when the package is ready to be uploaded to pub.dev. + path: ../mediapipe_task_text_platform_interface + flutter: + sdk: flutter + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^2.0.0 diff --git a/packages/mediapipe-task-text/mediapipe_task_text_android/test/mediapipe_task_text_android_test.dart b/packages/mediapipe-task-text/mediapipe_task_text_android/test/mediapipe_task_text_android_test.dart new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_android/test/mediapipe_task_text_android_test.dart @@ -0,0 +1 @@ + diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/.gitignore b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/.gitignore new file mode 100644 index 00000000..96486fd9 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/.metadata b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/.metadata new file mode 100644 index 00000000..6cab8543 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: 1ca183d55b24c0813b477478743df67ccca460a4 + channel: master + +project_type: package diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/CHANGELOG.md b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/CHANGELOG.md new file mode 100644 index 00000000..41cc7d81 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* TODO: Describe initial release. diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/LICENSE b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/LICENSE new file mode 100644 index 00000000..ba75c69f --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/LICENSE @@ -0,0 +1 @@ +TODO: Add your license here. diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/README.md b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/README.md new file mode 100644 index 00000000..02fe8eca --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/README.md @@ -0,0 +1,39 @@ + + +TODO: Put a short description of the package here that helps potential users +know whether this package might be useful for them. + +## Features + +TODO: List what your package can do. Maybe include images, gifs, or videos. + +## Getting started + +TODO: List prerequisites and provide or point to information on how to +start using the package. + +## Usage + +TODO: Include short and useful examples for package users. Add longer examples +to `/example` folder. + +```dart +const like = 'sample'; +``` + +## Additional information + +TODO: Tell users more about the package: where to find more information, how to +contribute to the package, how to file issues, what response they can expect +from the package authors, and more. diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/analysis_options.yaml b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/analysis_options.yaml new file mode 100644 index 00000000..a5744c1c --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/mediapipe_task_text_platform_interface.dart b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/mediapipe_task_text_platform_interface.dart new file mode 100644 index 00000000..e048f4d6 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/mediapipe_task_text_platform_interface.dart @@ -0,0 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'src/classification_result.dart'; +export 'src/mediapipe_task_text_method_channel.dart'; +export 'src/mediapipe_task_text_platform_interface.dart'; diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/src/classification_result.dart b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/src/classification_result.dart new file mode 100644 index 00000000..7c0fbb88 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/src/classification_result.dart @@ -0,0 +1,7 @@ +class ClassificationResult { + ClassificationResult(this.value); + factory ClassificationResult.fromJson(Map json) => + ClassificationResult(json['value']); + + final String value; +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/src/mediapipe_task_text_method_channel.dart b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/src/mediapipe_task_text_method_channel.dart new file mode 100644 index 00000000..3facac04 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/src/mediapipe_task_text_method_channel.dart @@ -0,0 +1,11 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'mediapipe_task_text_platform_interface.dart'; + +/// An implementation of [MediapipeTaskTextPlatform] that uses method channels. +class MethodChannelMediaPipeTaskText extends MediaPipeTaskTextPlatform { + /// The method channel used to interact with the native platform. + @visibleForTesting + final methodChannel = const MethodChannel('mediapipe_task_text'); +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/src/mediapipe_task_text_platform_interface.dart b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/src/mediapipe_task_text_platform_interface.dart new file mode 100644 index 00000000..96abe118 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/lib/src/mediapipe_task_text_platform_interface.dart @@ -0,0 +1,34 @@ +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'classification_result.dart'; +import 'mediapipe_task_text_method_channel.dart'; + +abstract class MediaPipeTaskTextPlatform extends PlatformInterface { + /// Constructs a MediaPipeTaskTextPlatform. + MediaPipeTaskTextPlatform() : super(token: _token); + + static final Object _token = Object(); + + static MediaPipeTaskTextPlatform _instance = MethodChannelMediaPipeTaskText(); + + /// The default instance of [MediaPipeTaskTextPlatform] to use. + /// + /// Defaults to [MethodChannelMediapipeTaskText]. + static MediaPipeTaskTextPlatform get instance => _instance; + + /// Platform-specific implementations should set this with their own + /// platform-specific class that extends [MediaPipeTaskTextPlatform] when + /// they register themselves. + static set instance(MediaPipeTaskTextPlatform instance) { + PlatformInterface.verifyToken(instance, _token); + _instance = instance; + } + + Future initClassifier(String modelPath) { + throw UnimplementedError('$this should implement initClassifier()'); + } + + Future classify(String value) { + throw UnimplementedError('$this should implement classify(String)'); + } +} diff --git a/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/pubspec.yaml b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/pubspec.yaml new file mode 100644 index 00000000..64bd0805 --- /dev/null +++ b/packages/mediapipe-task-text/mediapipe_task_text_platform_interface/pubspec.yaml @@ -0,0 +1,53 @@ +name: mediapipe_task_text_platform_interface +description: A new Flutter package project. +version: 0.0.1 +repository: https://github.com/google/flutter-mediapipe/tree/main/packages/mediapipe-task-text/mediapipe_task_text_platform_interface + +environment: + sdk: '>=3.0.0 <4.0.0' + flutter: ">=3.10.0" + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.1.4 + +dev_dependencies: + flutter_lints: ^2.0.0 + flutter_test: + sdk: flutter + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec +# The following section is specific to Flutter packages. +flutter: null + +# To add assets to your package, add an assets section, like this: +# assets: +# - images/a_dot_burr.jpeg +# - images/a_dot_ham.jpeg +# +# For details regarding assets in packages, see +# https://flutter.dev/assets-and-images/#from-packages +# +# An image asset can refer to one or more resolution-specific "variants", see +# https://flutter.dev/assets-and-images/#resolution-aware +# To add custom fonts to your package, add a fonts section here, +# in this "flutter" section. Each entry in this list should have a +# "family" key with the font family name, and a "fonts" key with a +# list giving the asset and other descriptors for the font. For +# example: +# fonts: +# - family: Schyler +# fonts: +# - asset: fonts/Schyler-Regular.ttf +# - asset: fonts/Schyler-Italic.ttf +# style: italic +# - family: Trajan Pro +# fonts: +# - asset: fonts/TrajanPro.ttf +# - asset: fonts/TrajanPro_Bold.ttf +# weight: 700 +# +# For details regarding fonts in packages, see +# https://flutter.dev/custom-fonts/#from-packages