当我尝试将图像复制到特定位置时,出现The method 'copy' isn't Defined for the type 'XFile' 错误。 错误。当我尝试将图像复制到设备中的特定位置时
详细错误:未为类型“XFile”定义方法“copy”。尝试将名称更正为现有方法的名称,或定义名为 'copy'.dartundefine_method 的方法
导入 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart' as syspaths;
class ImageInput extends StatefulWidget {
@override
_ImageInputState createState() => _ImageInputState();
}
class _ImageInputState extends State<ImageInput> {
File _storedImage;
Future<void> _takePicture() async {
final picker = ImagePicker();
final imageFile = await picker.pickImage(
source: ImageSource.camera,
maxWidth: 600,
);
setState(() {
_storedImage = File(imageFile.path);
});
final appDir = await syspaths.getApplicationDocumentsDirectory();
final fileName = path.basename(imageFile.path); …Run Code Online (Sandbox Code Playgroud) 我收到一个错误,例如:
无法从工厂构造函数访问实例成员。尝试删除对实例成员的引用。
有什么解决办法吗?
class DepartureModel {
String route;
String departureTime;
String arrivalTime;
String tourType;
List<String> daysOfWeek;
DepartureModel({
required this.route,
required this.departureTime,
required this.arrivalTime,
required this.tourType,
required this.daysOfWeek,
});
//method that assign values to respective datatype vairables
factory DepartureModel.fromJson(Map<String, dynamic> json) {
return DepartureModel(
route: json['route'],
departureTime: json['departureTime'],
arrivalTime: json['arrivalTime'],
tourType: json['tourType'],
daysOfWeek: json["daysOfWeek"].forEach(
(day) {
daysOfWeek.add(day);
},
),
);
}
Run Code Online (Sandbox Code Playgroud)