参数类型 'File' 无法分配给参数类型 'File '

The argument type 'File' can't be assigned to the parameter type 'File '

大家好,我对 flutter.I 比较陌生,不明白这个错误的含义。参数类型相同。我在“ Provider.of(context, listen: false).addPlace( _titleController.text, _pickedImage!);"

这是我收到错误消息的屏幕:

import 'dart:html';

import 'package:flutter/material.dart';
import 'package:great_places_app/Providers.dart/great_places.dart';
import 'package:great_places_app/Widgets/image_inputs.dart';
import 'package:provider/provider.dart';

class AddPlaceScreen extends StatefulWidget {
  const AddPlaceScreen({Key? key}) : super(key: key);
  static const routeName = '/add-place';

  @override
  _AddPlaceScreenState createState() => _AddPlaceScreenState();
}

class _AddPlaceScreenState extends State<AddPlaceScreen> {
  final _titleController = TextEditingController();
  File? _pickedImage;

  void _selectImage(File pickedImage) {
    _pickedImage = pickedImage;
  }

  void _savePlace() {
    if (_titleController.text.isEmpty || _pickedImage == null) {
      return;
    }
    Provider.of<GreatPlaces>(context, listen: false).addPlace(
        _titleController.text,
        _pickedImage!);  //this is where I am recieving the error
    Navigator.of(context).pop();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Add a New Place'),
      ),
      body: Column(
        // mainAxisAlignment: MainAxisAlignment.spaceBetween, no need because of expanded
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Expanded(
              child: SingleChildScrollView(
           
            child: Padding(
              padding: EdgeInsets.all(10),
              child: Column(
                children: [
                  
                  TextField(
                    decoration: InputDecoration(labelText: 'title'),
                    controller: _titleController,
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  imageInput(
                      _selectImage), 
                ],
              ),
            ),
          )),
          ElevatedButton.icon(
            onPressed: () {
              Navigator.of(context).pushNamed(AddPlaceScreen
                  .routeName); 
            },
            icon: Icon(Icons.add_location),
            label: Text('Add Place'),
          ),
        ],
      ),
    );
  }
}

这是加法函数:

void addPlace(String title, File image) {
    final newPlace = Place(
        id: DateTime.now().toString(),
        title: title,
        Image: image,
        location: null);
    _items.add(newPlace);
    notifyListeners();
  }

在此先感谢您的帮助

_AddPlaceScreenState 的代码使用 dart:html 中的 Filedart:html's File class is not the same as dart:io's File class,您的 addPlace 函数大概期望如此。

一般来说,如果您收到令人困惑的错误消息:

The argument type 'SomeType' can't be assigned to the parameter type 'SomeType'

表示您有不同类同名