I wrote a code which uses flutter_mobile_vision and morse to scan texts via mobile camera and covert those scanned texts into Morse code.
Here is my code:
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobile_vision/flutter_mobile_vision.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:lottie/lottie.dart';
import 'package:morse/morse.dart';
class OCRPage extends StatefulWidget {
@override
_OCRPageState createState() => _OCRPageState();
}
class _OCRPageState extends State<OCRPage> {
int _ocrCamera = FlutterMobileVision.CAMERA_BACK;
String _text = "TEXT";
Future<Null> _read() async {
List<OcrText> texts = [];
try {
texts = await FlutterMobileVision.read(
camera: _ocrCamera,
waitTap: true,
);
setState(() {
_text = texts[0].value;
});
} on Exception {
texts.add( OcrText('Failed to recognize text'));
}
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return SingleChildScrollView(
child: Center(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Lottie.asset('assets/scan-some-words.json', repeat: false),
SizedBox(height: 20),
Text(_text, style: GoogleFonts.orbitron(textStyle: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w500)), textAlign: TextAlign.center,),
SizedBox(height: 10),
Text(Morse(_text).encode(), style: GoogleFonts.orbitron(textStyle: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w500)),textAlign: TextAlign.center,),
SizedBox(height: 30),
ElevatedButton(
onPressed: _read,
child: new Text('Start Scanning'),
// color: Color(0xFFFF16CD),
// splashColor: Colors.orangeAccent,
),
SizedBox(height: 10),
Text('Tap on the text to convert into Morse Code', style: TextStyle(color: Color(0xffE6BBFC)),)
]
)
);
throw UnimplementedError();
}
}
Running this code returns the error
E/AndroidRuntime(24295): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Thread$State java.lang.Thread.getState()' on a null object reference E/AndroidRuntime(24295): at io.github.edufolly.fluttermobilevision.ui.CameraSource$FrameProcessingRunnable.release(CameraSource.java:1142) E/AndroidRuntime(24295): at io.github.edufolly.fluttermobilevision.ui.CameraSource$FrameProcessingRunnable.access$900(CameraSource.java:1119) E/AndroidRuntime(24295): at io.github.edufolly.fluttermobilevision.ui.CameraSource.release(CameraSource.java:334) E/AndroidRuntime(24295): at io.github.edufolly.fluttermobilevision.ui.CameraSourcePreview.release(CameraSourcePreview.java:85) E/AndroidRuntime(24295): at io.github.edufolly.fluttermobilevision.util.AbstractCaptureActivity.onDestroy(AbstractCaptureActivity.java:124) E/AndroidRuntime(24295): at android.app.Activity.performDestroy(Activity.java:8251) E/AndroidRuntime(24295): at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1364) E/AndroidRuntime(24295): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5290)
This seems to be a bug, I've added that in flutter_mobile_vision github issues... https://github.com/edufolly/flutter_mobile_vision/issues/71
Any idea how it can be fixed?