firebase_mlkit_language 1.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 86

ML Kit Natural Language Plugin #


A Flutter plugin to use the ML Kit Natural Language for Firebase API.

For Flutter plugins for other Firebase products, see

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

Usage #

To use this plugin, add firebase_mlkit_language as a dependency in your pubspec.yaml file. You must also configure Firebase for each platform project: Android and iOS (see the example folder or for step by step details).

iOS #

Versions 1.0.0+ use the latest ML Kit for Firebase version which requires a minimum deployment target of 9.0. You can add the line platform :ios, '9.0' in your iOS project Podfile.

Supported Languages #

All the supported languages can be found here.

Furthermore, they can be found within the SupportedLanguages class.

Using the ML Kit Language Identifier #

1. Create an instance of a language identifier #

Initialize a LanguageIdentifier.

final LanguageIdentifier languageIdentifier = FirebaseLanguage.instance.languageIdentifier()

2. Call processText(String) with languageIdentifier #

processText(String) returns List<LanguageLabel> in decreasing order of probability of detected language.

final List<LanguageLabel> labels = await languageIdentifier.processText('Sample Text');

3. Extract data #

<LanguageLabel> contains the language names and confidence of the prediction, accessible via .text and .confidence.

for (LanguageLabel label in labels) {
  final String text = label.text;
  final double confidence = label.confidence;

Using the ML Kit Language Translator #

Note #

Get an instance of ModelManager, and download the needed translation models(optional, results in faster first-use).


1. Create an instance of a language translator #

Initialize a LanguageTranslator.

final FirebaseLanguage.instance.languageTranslator(SupportedLanguages.lang, SupportedLanguages.lang);

2. Call processText(String) with languageTranslator #

processText(String) returns a string containing the text translated to the target language.

final String translatedString = await languageTranslator.processText('Sample Text');

Using the ML Kit Model Manager #

1. Create an instance of a model manager #

Initialize a ModelManager

final ModelManager modelManager = FirebaseLanguage.instance.modelManager()

2. Download Model using the model manager #

downloadModel() downloads the specified model to the device's local storage. It is recommended to download all the models needed to be used before translating to ensure a fast first-use. On a successful download, the string "Downloaded" will be returned.


3. Delete Model using the model manager #

deleteModel() deletes the specified model from the device's local storage. On a successful delete, the string "Deleted" will be returned. If the model specified is not present on the device, the string "Model not downloaded" will be returned.


4. View Models #

viewModels() returns a list of the BCP-47 language codes of all the languages downloaded onto the local storage of the device.


1.1.2 #

  • Minor updates

1.1.1 #

  • Minor updates

1.1.0 #

  • Added support for Android

1.0.1 #

  • Updated README, example

1.0.0 #

  • Updated README

0.0.1 #

  • Initial release


import 'package:flutter/material.dart';

import 'package:firebase_mlkit_language/firebase_mlkit_language.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  _MyAppState createState() => _MyAppState();

class _MyAppState extends State<MyApp> {
  void initState() {

  final inputTextController = TextEditingController();

  void dispose() {
    // Clean up the controller when the Widget is disposed

  var translatedText = "Translated Text";
  var inputText;
  var identifiedLang = "Detected Language";

  void onPressed() async {
    inputText = inputTextController.text;
    var result = await FirebaseLanguage.instance
            SupportedLanguages.English, SupportedLanguages.Spanish)
    setState(() {
      translatedText = result;

  void onPoked() async {
    inputText = inputTextController.text;
    var result = await FirebaseLanguage.instance

    setState(() {
      identifiedLang = result[0].languageCode; //returns most probable

  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text("Plug-In Example App"),
          body: new Container(
            padding: EdgeInsets.all(50),
            child: new Center(
              child: new Column(
                children: <Widget>[
                  new TextField(controller: inputTextController),
                  new SizedBox(height: 50),
                  new RaisedButton(
                      child: new Text("Translate",
                          style: TextStyle(color: Colors.white)),
                      onPressed: onPressed),
                  new SizedBox(height: 25),
                  new Container(
                    padding: EdgeInsets.all(20),
                    child: new SizedBox(
                        child: new Text(translatedText), height: 20),
                    decoration: new BoxDecoration(
                  new SizedBox(height: 20),
                  new RaisedButton(
                      child: new Text("Identify Language",
                          style: TextStyle(color: Colors.white)),
                      onPressed: onPoked),
                  new SizedBox(height: 25),
                  new Container(
                    padding: EdgeInsets.all(10),
                    child: new Text(identifiedLang),
                    decoration: new BoxDecoration(

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  firebase_mlkit_language: ^1.1.2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:firebase_mlkit_language/firebase_mlkit_language.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Maintenance suggestions

Package is getting outdated. (-0.27 points)

The package was last published 52 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
firebase_core ^0.4.0
test any