flutter - 发现多个文件的操作系统独立路径为 'META-INF/androidx.exifinterface_exifinterface.version'

标签 flutter firebase-mlkit

我正在使用 Google mlkit: ^0.9.0 扫描我的 Flutter 项目中的条形码,当我运行它时出现此错误:

Note: C:\flutter\.pub-cache\hosted\pub.dartlang.org\mlkit-0.9.0\android\src\main\java\com\azihsoyn\flutter\mlkit\MlkitPlugin.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> More than one file was found with OS independent path 'META-INF/androidx.exifinterface_exifinterface.version'

不知道是什么原因
这是我的 pubsec.yaml 文件:

name: flutter_test_barcode
description: A new Flutter application for test ocr

version: 1.0.0+1

environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  path_provider: 0.4.1
  mlkit: ^0.9.0
  image_picker: 0.4.12+1

dev_dependencies:
  flutter_test:
    sdk: flutter


flutter:

  uses-material-design: true

这是我的 Main.dart 文件:

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:mlkit/mlkit.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  File _file;
  List<VisionText> _currentLabels = <VisionText>[];

  FirebaseVisionTextDetector detector = FirebaseVisionTextDetector.instance;

  @override
  initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app'),
        ),
        body: _buildBody(),
        floatingActionButton: new FloatingActionButton(
          onPressed: () async {
            try {
              //var file = await ImagePicker.pickImage(source: ImageSource.camera);
              var file =
              await ImagePicker.pickImage(source: ImageSource.gallery);
              setState(() {
                _file = file;
              });
              try {
                var currentLabels = await detector.detectFromPath(_file?.path);
                setState(() {
                  _currentLabels = currentLabels;
                });
              } catch (e) {
                print(e.toString());
              }
            } catch (e) {
              print(e.toString());
            }
          },
          child: new Icon(Icons.camera),
        ),
      ),
    );
  }

  Widget _buildImage() {
    return SizedBox(
      height: 500.0,
      child: new Center(
        child: _file == null
            ? Text('No Image')
            : new FutureBuilder<Size>(
          future: _getImageSize(Image.file(_file, fit: BoxFit.fitWidth)),
          builder: (BuildContext context, AsyncSnapshot<Size> snapshot) {
            if (snapshot.hasData) {
              return Container(
                  foregroundDecoration:
                  TextDetectDecoration(_currentLabels, snapshot.data),
                  child: Image.file(_file, fit: BoxFit.fitWidth));
            } else {
              return new Text('Detecting...');
            }
          },
        ),
      ),
    );
  }

  Future<Size> _getImageSize(Image image) {
    Completer<Size> completer = new Completer<Size>();
    image.image.resolve(new ImageConfiguration()).addListener(
            (ImageInfo info, bool _) => completer.complete(
            Size(info.image.width.toDouble(), info.image.height.toDouble())));
    return completer.future;
  }

  Widget _buildBody() {
    return Container(
      child: Column(
        children: <Widget>[
          _buildImage(),
          _buildList(_currentLabels),
        ],
      ),
    );
  }

  Widget _buildList(List<VisionText> texts) {
    if (texts.length == 0) {
      return Text('Empty');
    }
    return Expanded(
      child: Container(
        child: ListView.builder(
            padding: const EdgeInsets.all(1.0),
            itemCount: texts.length,
            itemBuilder: (context, i) {
              return _buildRow(texts[i].text);
            }),
      ),
    );
  }

  Widget _buildRow(String text) {
    return ListTile(
      title: Text(
        "Text: ${text}",
      ),
      dense: true,
    );
  }
}

class TextDetectDecoration extends Decoration {
  final Size _originalImageSize;
  final List<VisionText> _texts;
  TextDetectDecoration(List<VisionText> texts, Size originalImageSize)
      : _texts = texts,
        _originalImageSize = originalImageSize;

  @override
  BoxPainter createBoxPainter([VoidCallback onChanged]) {
    return new _TextDetectPainter(_texts, _originalImageSize);
  }
}

class _TextDetectPainter extends BoxPainter {
  final List<VisionText> _texts;
  final Size _originalImageSize;
  _TextDetectPainter(texts, originalImageSize)
      : _texts = texts,
        _originalImageSize = originalImageSize;

  @override
  void paint(Canvas canvas, Offset offset, ImageConfiguration configuration) {
    final paint = new Paint()
      ..strokeWidth = 2.0
      ..color = Colors.red
      ..style = PaintingStyle.stroke;
    print("original Image Size : ${_originalImageSize}");

    final _heightRatio = _originalImageSize.height / configuration.size.height;
    final _widthRatio = _originalImageSize.width / configuration.size.width;
    for (var text in _texts) {
      print("text : ${text.text}, rect : ${text.rect}");
      final _rect = Rect.fromLTRB(
          offset.dx + text.rect.left / _widthRatio,
          offset.dy + text.rect.top / _heightRatio,
          offset.dx + text.rect.right / _widthRatio,
          offset.dy + text.rect.bottom / _heightRatio);
      //final _rect = Rect.fromLTRB(24.0, 115.0, 75.0, 131.2);
      print("_rect : ${_rect}");
      canvas.drawRect(_rect, paint);
    }

    print("offset : ${offset}");
    print("configuration : ${configuration}");

    final rect = offset & configuration.size;

    print("rect container : ${rect}");

    //canvas.drawRect(rect, paint);
    canvas.restore();
  }
}

我根据 Google Android X 兼容性文档更改了库版本,但错误仍然存​​在!请帮助我

最佳答案

最后通过更改mlkit 的版本库和pubspec.yaml 文件中的一些其他库解决了这个问题,我猜他们可能与此冲突。关键注意事项是 version number 之前的“^”符号应该被删除,以确保使用的是哪个 version number,而不是最新的可用版本。

关于flutter - 发现多个文件的操作系统独立路径为 'META-INF/androidx.exifinterface_exifinterface.version',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54841438/

相关文章:

Android Studio - 设备文件资源管理器停止工作

ios - MLKit iOS : Undefined symbols for architecture armv7

java - 我如何找到上下文并从 Android firebase ML-Kit BarcodeScannerProcessor onSuccess 开始一个新的 Activity

android - 在计算/隔离函数内运行 Firebase ML Vision API 调用

android - 是否可以量化 tflite 模型?

flutter - 如何让 ListView.builder() 小部件的高度成为整个堆栈的高度?

flutter - 使用 showMenu() 时如何处理 PopupMeniItem 按下

Flutter:将数据发送回特​​定列表项

flutter - 参数类型 'ModalRoute<Object?>?' 不能分配给参数类型 'PageRoute<dynamic>'

javascript - Nativescript 核心将 imageAsset 转换为 Imagesource ML 套件和相机接口(interface)