In this recipe, you will build a screen where users can type some text, and you will identify the language of the text. Follow these steps:
- In your pubspec.yaml file, add the latest version of the firebase_mlkit_language package:
firebase_mlkit_language: ^1.1.3
- In the ml.dart file, add a new async method, called identifyLanguage. The method takes String as a parameter, and returns a future of type String:
Future<String> identifyLanguage(String text) async {} - At the top of the indentifyLanguage method, declare four variables: String, a FirebaseLanguage instance, LanguageIdentifier, and a list of LanguageLabel objects:
String result = '';
final language = FirebaseLanguage.instance;
final identifier = language.languageIdentifier();
List<LanguageLabel> languages;
- After the declarations, insert a try/catch block: call the identifier.processText method to retrieve a list of LanguageLabel objects...