Flutter 图像选择器问题颤振

Flutter 图像选择器问题颤振,flutter,Flutter,这就是问题所在,我面临的是图像选择器 The argument type 'Future<File> (where File is defined in C:\Users\RIDDHI\AndroidStudioProjects\flutter\bin\cache\pkg\sky_engine\lib\io\file.dart)' can't be assigned to the parameter type 'Future<File> (where File is de

这就是问题所在,我面临的是图像选择器

The argument type 'Future<File> (where File is defined in C:\Users\RIDDHI\AndroidStudioProjects\flutter\bin\cache\pkg\sky_engine\lib\io\file.dart)' can't be assigned to the parameter type 'Future<File> (where File is defined in C:\Users\RIDDHI\AndroidStudioProjects\flutter\bin\cache\pkg\sky_engine\lib\html\html_dart2js.dart)'.
错误所在的代码

import 'dart:html';

import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:admin_app/db/category.dart';
import 'package:admin_app/db/brand.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';
import 'package:image_picker/image_picker.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:firebase_storage/firebase_storage.dart';

class AddProduct extends StatefulWidget {
@override
  _AddProductState createState() => _AddProductState();
}
class _AddProductState extends State<AddProduct> {
  CategoryService _categoryService = CategoryService();
  BrandService _brandService = BrandService();
  GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  TextEditingController productNameController = TextEditingController();
  TextEditingController quatityController = TextEditingController();
  List<DocumentSnapshot> brands = <DocumentSnapshot>[];
  List<DocumentSnapshot> categories = <DocumentSnapshot>[];
  List<DropdownMenuItem<String>> categoriesDropDown = <DropdownMenuItem<String>>[];
  List<DropdownMenuItem<String>> brandsDropDown = <DropdownMenuItem<String>>[];
  String _currentCategory;
  String _currentBrand;
  Color white = Colors.white;
  Color black = Colors.black;
  Color grey = Colors.grey;
  Color red = Colors.red;
  List<String> selectedSizes = <String>[];
  File _image1;
  File _image2;
  File _image3;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.1,
        backgroundColor: white,
        leading: Icon(Icons.close, color: black,),
        title: Text("add product", style: TextStyle(color: black),),
      ),
      body: Form(
        key: _formKey,
        child: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: OutlineButton(
                          borderSide: BorderSide(color: grey.withOpacity(0.5), width: 2.5),
                          onPressed: (){
                            _selectImage(ImagePicker.pickImage(source: ImageSource.gallery), 1);
                          },
                          child: _displayChild1()
                      ),
                    ),
                  ),

                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: OutlineButton(
                          borderSide: BorderSide(color: grey.withOpacity(0.5), width: 2.5),
                          onPressed: (){
                            _selectImage(ImagePicker.pickImage(source: ImageSource.gallery), 2);

                          },
                          child: _displayChild2()
                      ),
                    ),
                  ),

                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: OutlineButton(
                        borderSide: BorderSide(color: grey.withOpacity(0.5), width: 2.5),
                        onPressed: (){
                          _selectImage(ImagePicker.pickImage(source: ImageSource.gallery), 3);
                        },
                        child: _displayChild3(),
                      ),
                    ),
                  ),
                ],
              ),


  void _selectImage(Future<File> pickImage, int imageNumber) async{
    File tempImg = await pickImage;
    switch(imageNumber){
      case 1:  setState(() => _image1 = tempImg);
      break;
      case 2:  setState(() => _image2 = tempImg);
      break;
      case 3:  setState(() => _image3 = tempImg);
      break;
    }
  }

  Widget _displayChild1() {
    if(_image1 == null){
      return Padding(
        padding: const EdgeInsets.fromLTRB(14, 70, 14, 70),
        child: new Icon(Icons.add, color: grey,),
      );
    }else{
      return Image.file(_image1, fit: BoxFit.fill, width: double.infinity,);
    }
  }

  Widget _displayChild2() {
    if(_image2 == null){
      return Padding(
        padding: const EdgeInsets.fromLTRB(14, 70, 14, 70),
        child: new Icon(Icons.add, color: grey,),
      );
    }else{
      return Image.file(_image2, fit: BoxFit.fill, width: double.infinity,);
    }
  }

  Widget _displayChild3() {
    if(_image3 == null){
      return Padding(
        padding: const EdgeInsets.fromLTRB(14, 70, 14, 70),
        child: new Icon(Icons.add, color: grey,),
      );
    }else{
      return Image.file(_image3, fit: BoxFit.fill, width: double.infinity,);
    }
  }
错误主要是内联ImagePicker.pickImagesource:ImageSource.gallery

我在pubspec.yaml中添加了图像选择器,并导入了“package:image\u picker/image\u picker.dart”
如果有人能在这方面提供帮助,请告诉我。我读过不同的解决方案,但没有一个有效

请删除最近导入的“dart:html”;存档

并使用此导入:

import 'dart:io';
而不是导入“dart:html”


希望对您有所帮助:D

请删除您最近导入的“dart:html”;存档

并使用此导入:

import 'dart:io';
而不是导入“dart:html”


希望对您有所帮助:D

更改/删除您的“dart:html”导入以导入“dart:io”;这可以解决你的问题。像这样:

import 'dart:io';
不导入“dart:html”


现在应该可以工作了:

更改/删除您的“dart:html”导入以导入“dart:io”;这可以解决你的问题。像这样:

import 'dart:io';
不导入“dart:html”


现在应该可以工作了:

不要从dart.htmlshow导入文件。我已经将导入更改/删除您的“dart:html”导入添加到导入“dart:io”;这可以解决您的问题。非常感谢@Chichebedo不要从dart.htmlshow导入文件。我已将导入更改/删除您的“dart:html”导入到导入“dart:io”;这可以解决你的问题。非常感谢@Chichebe