firebase_mlkit_language 1.1.1 copy "firebase_mlkit_language: ^1.1.1" to clipboard
firebase_mlkit_language: ^1.1.1 copied to clipboard

outdated

Firebase ML Kit Language Plugin for Flutter, enables Language Detection and Translation between 59 Languages

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:firebase_mlkit_language/firebase_mlkit_language.dart';

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  final inputTextController = TextEditingController();

  @override
  void dispose() {
    // Clean up the controller when the Widget is disposed
    inputTextController.dispose();
    super.dispose();
  }

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

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text("Plug-In Example App"),
            backgroundColor: Colors.blue,
          ),
          body: new Container(
            padding: EdgeInsets.all(50),
            child: new Center(
              child: new Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  new TextField(controller: inputTextController),
                  new SizedBox(height: 50),
                  new RaisedButton(
                      child: new Text("Translate",
                          style: TextStyle(color: Colors.white)),
                      color: Colors.blue,
                      onPressed: onPressed),
                  new SizedBox(height: 25),
                  new Container(
                    padding: EdgeInsets.all(20),
                    child: new SizedBox(
                        child: new Text(translatedText), height: 20),
                    decoration: new BoxDecoration(
                      color: Colors.black.withOpacity(0.05),
                    ),
                  ),
                  new SizedBox(height: 20),
                  new RaisedButton(
                      child: new Text("Identify Language",
                          style: TextStyle(color: Colors.white)),
                      color: Colors.blue,
                      onPressed: onPoked),
                  new SizedBox(height: 25),
                  new Container(
                    padding: EdgeInsets.all(10),
                    child: new Text(identifiedLang),
                    decoration: new BoxDecoration(
                      color: Colors.black.withOpacity(0.05),
                    ),
                  ),
                ],
              ),
            ),
          )),
    );
  }
}
28
likes
0
pub points
36%
popularity

Publisher

verified publisherrishabnayak.com

Firebase ML Kit Language Plugin for Flutter, enables Language Detection and Translation between 59 Languages

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on firebase_mlkit_language