content: import 'package:flutter/material.dart';
  import 'package:flutter/cupertino.dart';
  
  import 'package:learning_input_image/learning_input_image.dart';
  import 'package:learning_text_recognition/learning_text_recognition.dart';
  import 'package:provider/provider.dart';
  
  class LearningTextRecognition extends StatefulWidget {
    @override
    _LearningTextRecognitionState createState() =>
        _LearningTextRecognitionState();
  }
  
  class _LearningTextRecognitionState extends State<LearningTextRecognition> {
    TextRecognition? _textRecognition = TextRecognition();
  
    /* TextRecognition? _textRecognition = TextRecognition(
      options: TextRecognitionOptions.Japanese
    ); */
  
    @override
    void dispose() {
      _textRecognition?.dispose();
      super.dispose();
    }
  
    Future<void> _startRecognition(InputImage image) async {
      LearningTextRecognitionState state =
          Provider.of<LearningTextRecognitionState>(context, listen: false);
  
      if (state.isNotProcessing) {
        state.startProcessing();
        state.image = image;
        state.data = await _textRecognition?.process(image);
        state.stopProcessing();
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return InputCameraView(
        mode: InputCameraMode.gallery,
        title: 'Text Recognition',
        onImage: _startRecognition,
        overlay: Consumer<LearningTextRecognitionState>(
          builder: (_, state, __) {
            if (state.isNotEmpty) {
              return Center(
                child: Container(
                  padding: EdgeInsets.symmetric(vertical: 10, horizontal: 16),
                  decoration: BoxDecoration(
                    color: Colors.white.withOpacity(0.8),
                    borderRadius: BorderRadius.all(Radius.circular(4.0)),
                  ),
                  child: Text(
                    state.text,
                    style: TextStyle(
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                ),
              );
            }
  
            return Container();
          },
        ),
      );
    }
  }
  
  class LearningTextRecognitionState extends ChangeNotifier {
    InputImage? _image;
    RecognizedText? _data;
    bool _isProcessing = false;
  
    InputImage? get image => _image;
    RecognizedText? get data => _data;
    String get text => _data!.text;
    bool get isNotProcessing => !_isProcessing;
    bool get isNotEmpty => _data != null && text.isNotEmpty;
  
    void startProcessing() {
      _isProcessing = true;
      notifyListeners();
    }
  
    void stopProcessing() {
      _isProcessing = false;
      notifyListeners();
    }
  
    set image(InputImage? image) {
      _image = image;
      notifyListeners();
    }
  
    set data(RecognizedText? data) {
      _data = data;
      notifyListeners();
    }
  }
  