简体   繁体   English

Flutter firebase_ml_vision 错误与异步函数、getImage 和pickFile

[英]Flutter firebase_ml_vision errors with async function, getImage and pickedFile

How to resolve the following errors:如何解决以下错误:

  1. The await expression can only be used in an async function.Try marking the function body with async. await 表达式只能用在 async 函数中。尝试用 async 标记函数体。
  2. Instance member 'getImage' can't be accessed using static access.无法使用静态访问访问实例成员“getImage”。
  3. The argument type PickedFile can't be assigned to the parameter type File.参数类型 PickedFile 不能分配给参数类型 File。

//Code Below //代码如下

import 'package:firebase_ml_vision/firebase_ml_vision.dart';

import 'package:flutter/material.dart';

import 'package:image_picker/image_picker.dart';

void main() async {
  runApp(Home());
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    final imageFile = await ImagePicker.getImage(
      source: ImageSource.camera,
    );

    final image = FirebaseVisionImage.fromFile(imageFile);

    return Scaffold(
      appBar: AppBar(title: Text("Mystify",),),
    );
  }
}

I face the same problem and did this.我面临同样的问题并做到了这一点。

await Future.delayed(new Duration(milliseconds: 1000))
        .whenComplete(() => () async {
              File foo = File(pickedFile.path);

              final image = FirebaseVisionImage.fromFile(foo);

对于颤振版本 2,使用 getImage 而不是 pickImage

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Flutter 上的 firebase_ml_vision 中计算人脸的函数 - Function to count faces in firebase_ml_vision on Flutter Flutter firebase_ml_vision 构建失败,出现异常 - Flutter firebase_ml_vision build failed with exception 将 firebase_ml_vision 添加到 flutter 引发错误“未知类型名称”FIRVisionCloudLabelDetector” - Add firebase_ml_vision to flutter raise an error 'Unknown type name 'FIRVisionCloudLabelDetector' firebase_ml_vision 中断 IOS 构建,修复 Windows 机器 - firebase_ml_vision breaks IOS build, fix for Windows machine FlutterFire Firebase_ml_vision:PlatformException(错误 13,com.firebase.ml,条码引擎为零。,空) - FlutterFire Firebase_ml_vision: PlatformException(Error 13, com.firebase.ml, Barcode engine is nil., null) "Firebase ML Vision 软件包因颤振而停产" - Firebase ML Vision package is DISCONTINUED for flutter 在Firebase ml视觉颤动中,Face对象的属性始终为null - Attributes of Face object is always null in firebase ml vision flutter 在 Compute/Isolate 函数中运行 Firebase ML Vision API 调用 - Running the Firebase ML Vision API calls inside a Compute/Isolate function 等待两个异步Firebase ml视觉方法结果在第三种方法中使用它们的最佳方法 - Best way to wait for two async firebase ml vision method results to use them in a third method Firebase ML-vision 和 admob 插件在同一个 Flutter 项目问题 - 播放服务版本冲突 - Firebase ML-vision and admob plugins in same Flutter project problem - play services version conflict
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM