diff --git a/packages/example/lib/vision_detector_views/detector_view.dart b/packages/example/lib/vision_detector_views/detector_view.dart index 624310c5..fb5bffbb 100644 --- a/packages/example/lib/vision_detector_views/detector_view.dart +++ b/packages/example/lib/vision_detector_views/detector_view.dart @@ -57,6 +57,7 @@ class _DetectorViewState extends State { ) : GalleryView( title: widget.title, + text: widget.text, onImage: widget.onImage, onDetectorViewModeChanged: _onDetectorViewModeChanged); } diff --git a/packages/example/lib/vision_detector_views/digital_ink_recognizer_view.dart b/packages/example/lib/vision_detector_views/digital_ink_recognizer_view.dart index ca178dd1..7f34fb00 100644 --- a/packages/example/lib/vision_detector_views/digital_ink_recognizer_view.dart +++ b/packages/example/lib/vision_detector_views/digital_ink_recognizer_view.dart @@ -11,9 +11,20 @@ class DigitalInkView extends StatefulWidget { class _DigitalInkViewState extends State { final DigitalInkRecognizerModelManager _modelManager = DigitalInkRecognizerModelManager(); - final String _language = 'en-US'; - late final DigitalInkRecognizer _digitalInkRecognizer = - DigitalInkRecognizer(languageCode: _language); + var _language = 'en'; + // Codes from https://developers.google.com/ml-kit/vision/digital-ink-recognition/base-models?hl=en#text + final _languages = [ + 'en', + 'es', + 'fr', + 'hi', + 'it', + 'ja', + 'pt', + 'ru', + 'zh-Hani', + ]; + var _digitalInkRecognizer = DigitalInkRecognizer(languageCode: 'en'); final Ink _ink = Ink(); List _points = []; String _recognizedText = ''; @@ -31,6 +42,45 @@ class _DigitalInkViewState extends State { body: SafeArea( child: Column( children: [ + SizedBox(height: 8), + Padding( + padding: EdgeInsets.symmetric(horizontal: 16), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + _buildDropdown(), + ElevatedButton( + onPressed: _isModelDownloaded, + child: Text('Check Model'), + ), + ElevatedButton( + onPressed: _downloadModel, + child: Icon(Icons.download), + ), + ElevatedButton( + onPressed: _deleteModel, + child: Icon(Icons.delete), + ), + ], + ), + ), + SizedBox(height: 8), + Padding( + padding: EdgeInsets.symmetric(horizontal: 16), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ElevatedButton( + onPressed: _recogniseText, + child: Text('Read Text'), + ), + ElevatedButton( + onPressed: _clearPad, + child: Text('Clear Pad'), + ), + ], + ), + ), Expanded( child: GestureDetector( onPanStart: (DragStartDetails details) { @@ -69,50 +119,39 @@ class _DigitalInkViewState extends State { 'Candidates: $_recognizedText', style: TextStyle(fontSize: 23), ), - Padding( - padding: EdgeInsets.symmetric(horizontal: 16), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ElevatedButton( - onPressed: _recogniseText, - child: Text('Read Text'), - ), - ElevatedButton( - onPressed: _clearPad, - child: Text('Clear Pad'), - ), - ], - ), - ), - SizedBox(height: 8), - Padding( - padding: EdgeInsets.symmetric(horizontal: 16), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ElevatedButton( - onPressed: _isModelDownloaded, - child: Text('Check Model'), - ), - ElevatedButton( - onPressed: _downloadModel, - child: Text('Download'), - ), - ElevatedButton( - onPressed: _deleteModel, - child: Text('Delete'), - ), - ], - ), - ), - SizedBox(height: 8), ], ), ), ); } + Widget _buildDropdown() => DropdownButton( + value: _language, + icon: const Icon(Icons.arrow_downward), + elevation: 16, + style: const TextStyle(color: Colors.blue), + underline: Container( + height: 2, + color: Colors.blue, + ), + onChanged: (String? lang) { + if (lang != null) { + setState(() { + _language = lang; + _digitalInkRecognizer.close(); + _digitalInkRecognizer = + DigitalInkRecognizer(languageCode: _language); + }); + } + }, + items: _languages.map>((lang) { + return DropdownMenuItem( + value: lang, + child: Text(lang), + ); + }).toList(), + ); + void _clearPad() { setState(() { _ink.strokes.clear(); diff --git a/packages/example/lib/vision_detector_views/text_detector_view.dart b/packages/example/lib/vision_detector_views/text_detector_view.dart index bf7c1d4d..0ee9c083 100644 --- a/packages/example/lib/vision_detector_views/text_detector_view.dart +++ b/packages/example/lib/vision_detector_views/text_detector_view.dart @@ -11,8 +11,8 @@ class TextRecognizerView extends StatefulWidget { } class _TextRecognizerViewState extends State { - final TextRecognizer _textRecognizer = - TextRecognizer(script: TextRecognitionScript.latin); + var _script = TextRecognitionScript.latin; + var _textRecognizer = TextRecognizer(script: TextRecognitionScript.latin); bool _canProcess = true; bool _isBusy = false; CustomPaint? _customPaint; @@ -28,16 +28,66 @@ class _TextRecognizerViewState extends State { @override Widget build(BuildContext context) { - return DetectorView( - title: 'Text Detector', - customPaint: _customPaint, - text: _text, - onImage: _processImage, - initialCameraLensDirection: _cameraLensDirection, - onCameraLensDirectionChanged: (value) => _cameraLensDirection = value, + return Scaffold( + body: Stack(children: [ + DetectorView( + title: 'Text Detector', + customPaint: _customPaint, + text: _text, + onImage: _processImage, + initialCameraLensDirection: _cameraLensDirection, + onCameraLensDirectionChanged: (value) => _cameraLensDirection = value, + ), + Positioned( + top: 30, + left: 100, + right: 100, + child: Row( + children: [ + Spacer(), + Container( + decoration: BoxDecoration( + color: Colors.black54, + borderRadius: BorderRadius.circular(10.0), + ), + child: Padding( + padding: const EdgeInsets.all(4.0), + child: _buildDropdown(), + )), + Spacer(), + ], + )), + ]), ); } + Widget _buildDropdown() => DropdownButton( + value: _script, + icon: const Icon(Icons.arrow_downward), + elevation: 16, + style: const TextStyle(color: Colors.blue), + underline: Container( + height: 2, + color: Colors.blue, + ), + onChanged: (TextRecognitionScript? script) { + if (script != null) { + setState(() { + _script = script; + _textRecognizer.close(); + _textRecognizer = TextRecognizer(script: _script); + }); + } + }, + items: TextRecognitionScript.values + .map>((script) { + return DropdownMenuItem( + value: script, + child: Text(script.name), + ); + }).toList(), + ); + Future _processImage(InputImage inputImage) async { if (!_canProcess) return; if (_isBusy) return;