Siva A
Siva A

Reputation: 21

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.
  2. Instance member 'getImage' can't be accessed using static access.
  3. The argument type PickedFile can't be assigned to the parameter type 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",),),
    );
  }
}

Upvotes: 1

Views: 195

Answers (2)

Nidhi
Nidhi

Reputation: 1

use getImage instead of pickImage for flutter version 2

Upvotes: -1

Mustafa yıldiz
Mustafa yıldiz

Reputation: 385

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);

Upvotes: 0

Related Questions