1

This is the issue, I'm facing on the image picker

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)'.

My code where the error is

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

The error is mainly inline ImagePicker.pickImage(source: ImageSource.gallery)

I have added the image picker in pubspec.yaml, as well as imported 'package:image_picker/image_picker.dart' Please if someone could help in the same. I have read different solutions but none of them worked

5
  • 1
    do not import File from dart.html Commented Aug 27, 2020 at 6:16
  • show you import also. Commented Aug 27, 2020 at 6:29
  • I have added the imports Commented Aug 27, 2020 at 10:38
  • 1
    Change/delete your 'dart:html' import to import 'dart:io'; that could fix the issue you're having. Commented Aug 27, 2020 at 10:51
  • You're welcome :) @RiddhiDua. I've posted the answer, please do well to accept it as the correct answer. Thanks! Commented Aug 27, 2020 at 20:56

2 Answers 2

2

Change/delete your 'dart:html' import to import 'dart:io'; that could fix the issue you're having. Like so:

import 'dart:io';

NOT import 'dart:html';

Should work now :)

Sign up to request clarification or add additional context in comments.

Comments

1

Please delete your recent import import 'dart:html'; for File

And use this import :

import 'dart:io';

instead of this import 'dart:html';

hope it will be help :D

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.