flutter 错误:参数类型'String'无法指派给参数类型'List< Object>'

jaql4c8m  于 2022-12-14  发布在  Flutter
关注(0)|答案(1)|浏览(155)
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)

我尝试了stackoverflow,我发现File()方法只使用一个参数File(文件路径),但我发现该错误非常意外 Error imageMy pubspec.yaml代码如下:

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

//从file_picker套件汇入

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

//他的行也显示了我的错误

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

我在stackoverflow上搜索了一下,但对我不起作用

hs1ihplo

hs1ihplo1#

我尝试了stackoverflow,发现File()方法只使用一个参数File(文件路径)
您正在描述使用dart:io 's File class的程式码,但您的程式码使用的是dart:html 's File class。它们不是相同的类别,无法互换使用。

相关问题