Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 类型';列表<;动态>';不是类型为';列表<;附件>';_Flutter_Email Attachments_Mailer_Dynamic List - Fatal编程技术网

Flutter 类型';列表<;动态>';不是类型为';列表<;附件>';

Flutter 类型';列表<;动态>';不是类型为';列表<;附件>';,flutter,email-attachments,mailer,dynamic-list,Flutter,Email Attachments,Mailer,Dynamic List,我使用照相机/多媒体资料获取图像,然后我想将它们附加到电子邮件(我用于此),但当我尝试发送电子邮件时,我收到以下错误: type“List”不是“List”类型的子类型。 有没有办法将动态列表转换为附件列表 这是我的代码: 我使用FormBuilderImagePicker小部件获取图像: FormBuilderImagePicker( attribute: 'image', onChanged: (value) { _attachments.add(value); debugPr

我使用照相机/多媒体资料获取图像,然后我想将它们附加到电子邮件(我用于此),但当我尝试发送电子邮件时,我收到以下错误:

type“List”不是“List”类型的子类型。

有没有办法将动态列表转换为附件列表

这是我的代码:

我使用FormBuilderImagePicker小部件获取图像:

FormBuilderImagePicker(
 attribute: 'image',
 onChanged: (value) {
  _attachments.add(value);
  debugPrint('attachments: $_attachments');
},
maxImages: 3,
defaultImage:
AssetImage('assets/images/icons8-plus-64.png'),
validators: [
 FormBuilderValidators.required(),
],
),
这是我发送电子邮件的代码:

  void sendEmailWithoutPosition(
  String name,
  String destination,
  String subject,
  String description,
  String email,
  String number,
  List<Attachment> attachments,
  BuildContext context) async {
message = Message()
  ..from = Address(username, name)
  ..recipients.add(destination)
  ..subject = ' Petiție ${subject.toString()} - aplicația e-Rădăuți'
  ..html = 'Către, ${destination.toString()} <br><br> Stimată doamnă/ Stimate domn,'
      '<br><br>Subsemnatul ${name.toString()}, vă supun atenției următoarea problemă:<br><br>'
      '$description<br><br>În conformitate cu atribuțiile pe care le aveți, vă rog să luați'
      ' măsurile ce se impun.<br><br>'
      'Prezenta sesizare reprezintă o petiție în sensul O.G. nr. 27/2002 privind activitatea de soluționare a petițiilor și '
      'a fost transmisă prin intermediul aplicației mobile e-Rădăuți, dezvoltată'
      ' de Ascociația Rădăuțiul Civic, prin funcționalitatea „Sesizează o problemă”.<br><br>'
      'Vă rog să îmi transmiteți răspunsul în termenul legal la adresa $email'
      '.<br><br>Cu stimă,<br><br>'
      '     $name<br><br>     Tel: $number/$email'
  ..attachments.addAll(attachments);
tryToSendEmail(message);
}

Future<bool> tryToSendEmail(var message) async {
final smtpServer = gmail(username, password);
try {
  final sendReport = await send(message, smtpServer);
  debugPrint('Message sent: ' + sendReport.toString());
} on MailerException catch (e) {
  print('Message not sent.');
  for (var p in e.problems) {
    print('Problem: ${p.code}: ${p.msg}');
  }
}
}
void sendmailwithoutposition(
字符串名,
字符串目的地,
字符串主题,
字符串描述,
字符串电子邮件,
字符串编号,

通过深入分析包的结构,列出我建议您使用的构造函数:附件是一个抽象类,不能简单地进行铸造。根据附件的类型,您可以执行以下操作:

//FOR FILE ATTACHMENTS
List<Attachment> listAttachments = _attachments.map((e) => FileAttachment(e.file)).toList();
//FOR STRING ATTACHMENTS
List<Attachment> listAttachments = _attachments.map((e) => StringAttachment(e.data)).toList();
//用于文件附件
名单


更新:我查看了您正在使用的库,但它缺少文档。不要使用onChanged尝试使用onImage。这样,每次选择图像时,您都应该获得所需的数据。

通过深入研究包的结构,我建议您使用常量构造函数:附件是一个抽象类,不能简单地进行铸造。根据附件的类型,您可以执行以下操作:

//FOR FILE ATTACHMENTS
List<Attachment> listAttachments = _attachments.map((e) => FileAttachment(e.file)).toList();
//FOR STRING ATTACHMENTS
List<Attachment> listAttachments = _attachments.map((e) => StringAttachment(e.data)).toList();
//用于文件附件
名单



更新:我查看了您正在使用的库,但它缺少文档。不要使用onChanged尝试使用onImage。这样,每次选择图像时,您都应该获得所需的数据。

我认为您应该传递
列表
附件,而不是
列表
。试试看。

我认为你应该传递
列表
附件,而不是
列表
。试试看。

仅仅通过查看stacktrace就很难理解这个问题。你能给我们一些代码来更好地理解你的问题的范围吗?哦,我的大部分代码来自两个包中的文档,但我肯定不会发布他说:“我认为最相关的部分是当你列出某事=某物时。这是为了理解什么是“某物”并查看是否可以将该列表的内容映射到attachments@AndreaCostanzo1我已经添加了我试图映射列表的方式和我得到的错误。由于附件是一个抽象类,您不能简单地强制转换。您必须使用构造函数正确创建附件。我在下面发布了一个答案,以便更好地了解你应该处理这个问题。仅仅通过查看stacktrace很难理解这个问题。你能给我们一些代码来更好地理解你的问题范围吗?哦,我的大部分代码来自两个包中的文档,但我肯定会发布代码。我想最相关的部分是当你列出某物=某物时。这要取消理解什么是“某物”并查看是否可以将该列表的内容映射到attachments@AndreaCostanzo1我已经添加了我试图映射列表的方式和我得到的错误。由于附件是一个抽象类,您不能简单地强制转换。您必须使用构造函数正确创建附件。我在下面发布了一个答案,以便更好地了解你应该处理它说:未处理的异常:NoSuchMethodError:类'\u File'没有实例getter'File'。好吧,路易斯,如果“e”已经是一个文件,你必须做(e)=>文件附件(e)。如果你给我更多关于“e”属于哪个类的信息,我可以更新上面的代码,使其适用于你的特定情况,如果我只写“e”我收到相同的错误:未处理的异常:类型“List”不是类型“List”的子类型"要获取imagesLuis,您使用的包的类缺少文档。我试图查看代码,但有时会感到困惑。它有一个onImage方法,但似乎没有被调用。请尝试使用该方法,否则会在他们的github页面上打开一个问题,要求从文档中解释该特定类不清楚。好的,谢谢你,但我做了类似以下的事情:file1=FileAttachments(attachments[1]);listaachments=[file1];对于这3张图片,我知道它不是什么好东西,但是的,它现在工作了PS attachments是tyoe列表,listAttachments是Listit类型它说:未处理的异常:NoSuchMethodError:Class“\u File”没有实例getter”File。好的,路易斯,如果“e”已经是一个文件,你必须做(e)=>FileAttachment(e)。如果您给我更多关于“e”类所属的信息,我可以更新上面的代码,使其适用于您的特定情况。如果我只说“e”,我会得到相同的错误:未处理的异常:“List”类型不是“List”类型的子类型"要获取imagesLuis,您使用的包的类缺少文档。我试图查看代码,但有时会感到困惑。它有一个onImage方法,但似乎没有被调用。请尝试使用该方法,否则会在他们的github页面上打开一个问题,要求从文档中解释该特定类不清楚。好的,谢谢你,但我做了类似以下的事情:file1=FileAttachments(attachments[1]);listaachments=[file1];对于3张图片,我知道这不是什么好东西,但是的,它现在可以工作PS附件属于tyoe列表,列表附件属于列表类型我在发布此问题之前尝试了此方法,但谢谢我在发布此问题之前尝试了此方法,但谢谢