error: The argument type 'String' can't be assigned to the parameter type 'List<Object>'

456 Views Asked by At
file=File(platformFile!.path.toString());this line is showing me 2 erros, saying 2 positional argument expected, found 1 in my flutter window app
[enter image description here](https://i.stack.imgur.com/aACww.png)

I tried stackoverflow there i found File() method taking only one argument File(file path) but it through me that error very unexpected  Error image My pubspec.yaml here's the code:

import 'dart:html';
import 'package:flutter/material.dart';
import 'package:file_picker/file_picker.dart'; 

//imports from file_picker package

class detailForm extends StatefulWidget {
  const detailForm({Key? key}) : super(key: key);

  @override
  State<detailForm> createState() => _detailFormState();
}

class _detailFormState extends State<detailForm> {
  File? file;
  PlatformFile? platformFile;
  // dynamic imageFile=NetworkImage('');
  void pickFile() async {
    FilePickerResult? result = await FilePicker.platform
        .pickFiles(type: FileType.image, allowMultiple: false);
    if (result == null) return;
    PlatformFile file = result.files.single;
    if (result != null) {
      platformFile = result.files.single;

      // List plat=platformFile!.path;
      file = File(platformFile!.path.toString()); //The line that was throughing me error
    }
    print(file.name);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        height: 660.0,
        width: 500.0,
        // color: Colors.red,
        decoration: BoxDecoration(
            border: Border.all(
          color: Colors.black26,
          width: 1.0,
        )),
        child: Material(
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.only(left: 8.0, top: 8.0),
                child: Row(
                  children: [
                    Text(
                      'Fill Details :',
                      style:
                          TextStyle(fontSize: 10, fontWeight: FontWeight.bold),
                    ),
                    Text(
                      'Products and Customer',
                      style: TextStyle(
                        fontSize: 10,
                      ),
                    )
                  ],
                ),
              ),
              SizedBox(
                height: 2.0,
              ),
              Divider(
                color: Colors.black26,
              ),
              Row(
                children: [
                  InkWell(
                    child: Container(
                      color: Colors.red,
                      width: 100.0,
                      height: 100.0,
                    ),
                    onTap: pickFile,
                  ),
                  Image.file(File(file));  

//his line also shown me error

                ],
              )
            ],
          ),
        ));
  }
}

I searched on stackoverflow about that, but doesn't worked for me

1

There are 1 best solutions below

0
smorgan On

I tried stackoverflow there i found File() method taking only one argument File(file path)

You are describing code that uses dart:io's File class, but your code is using dart:html's File class. They are not the same class, and can't be used interchangeably.