This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//app/build.gradle | |
dependencies { | |
implementation 'com.google.firebase:firebase-ml-vision:24.1.0' | |
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:16.1.1' | |
implementation 'com.google.mlkit:language-id:16.1.1' | |
implementation 'com.google.mlkit:translate:16.1.1' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<application ...> | |
... | |
<meta-data | |
android:name="com.google.mlkit.vision.DEPENDENCIES" | |
android:value="ocr" /> | |
<!-- To use multiple models: android:value="ocr,model2,model3" --> | |
</application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Capture { | |
File image; | |
final picker = ImagePicker(); //instantiate the image picker object | |
Future<CapturedImage> getImage() async { | |
final pickedFile = | |
await picker.getImage(source: ImageSource.camera, imageQuality: 50); //capture the image | |
if (pickedFile != null) { | |
image = File(pickedFile.path); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CapturedImage { | |
final File image; | |
final String error; | |
CapturedImage(this.image, this.error); | |
CapturedImage.fromFile(File file) | |
: image = file, | |
error = ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
dependencies: | |
flutter: | |
sdk: flutter | |
... | |
firebase_ml_vision: ^0.9.8 | |
flutter_language_identification: ^0.1.0 | |
translator: ^0.1.5 | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Map<String, dynamic> supportedLanguages = { | |
'af': 'Afrikaans', | |
'am': 'Amharic', | |
... | |
... | |
... | |
'zh': 'Chinese', | |
'zu': 'Zulu', | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
List<DropdownMenuItem<String>> languages = [ | |
for (int i = 0; i < supportedLanguages.length; i++) | |
DropdownMenuItem<String>( | |
child: Text(List.from(supportedLanguages.values)[i]), | |
value: List.from(supportedLanguages.keys)[i], | |
), | |
]; | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
//Initial State | |
class RecogniseTextInitial extends RecogniseTextState {} | |
//state emitted when text is being recognised | |
class RecognisingText extends RecogniseTextState {} | |
//final state when text has been recognised successfully | |
class RecognisedText extends RecogniseTextState { | |
final String text, language, languageCode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
//Only one event to recognise text | |
class RecogniseText extends RecogniseTextEvent { | |
final File image; | |
RecogniseText(this.image); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RecogniseTextBloc extends Bloc<RecogniseTextEvent, RecogniseTextState> { | |
RecogniseTextBloc() : super(RecogniseTextInitial()); | |
MLKit mlKit = MLKit(); | |
@override | |
Stream<RecogniseTextState> mapEventToState( | |
RecogniseTextEvent event, | |
) async* { | |
yield RecogniseTextInitial(); |
OlderNewer