Flutter错误:找不到“文件”类型。这里发生了什么?

时间:2019-05-09 16:13:40

标签: flutter flutter-dependencies

我正在尝试将firebase_ml_visionimage_picker一起使用。

代码如下:

import 'package:flutter/material.dart';

import 'package:image_picker/image_picker.dart';
import 'package:firebase_ml_vision/firebase_ml_vision.dart';

void main() => runApp(MyHomePage());

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
    FirebaseVisionImage visionImage;

    final BarcodeDetector barcodeDetector = FirebaseVision.instance.barcodeDetector();
    final TextRecognizer textRecognizer = FirebaseVision.instance.textRecognizer();
    final ImageLabeler labeler = FirebaseVision.instance.imageLabeler(
          ImageLabelerOptions(confidenceThreshold: 0.75),
    );
    final FaceDetector faceDetector = FirebaseVision.instance.faceDetector();

    void detections() async {
        final VisionText visionText = await textRecognizer.processImage(visionImage);
    }

  File _image;

  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);
    var something = await ImagePicker.pickImage(source: ImageSource.camera);

    setState(() {
      this.visionImage = FirebaseVisionImage.fromFile(something);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Image Picker Example'),
      ),
      body: Center(
        child: _image == null
            ? Text('No image selected.')
            : Image.file(_image),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: getImage,
        tooltip: 'Pick Image',
        child: Icon(Icons.add_a_photo),
      ),
    );
  }
}

但是我无法使用File数据类型,这是我得到的错误: Error

这是我运行flutter doctor时得到的结果: Doctor

这是我运行flutter --version时得到的结果: Version

我对Flutter还是很陌生,所以如果您还有其他需要,请告诉我。

谢谢!

1 个答案:

答案 0 :(得分:2)

dart:io中的文件类型丢失了。将import 'dart:io';添加到文件顶部。