【发布时间】:2020-08-20 10:49:55
【问题描述】:
我正在开发一个邮件应用程序,但当我尝试与receive_sharing_intent package共享文件以通过电子邮件发送时遇到了问题
我可以在应用程序中获取文件及其路径和所有内容,但是我需要将用户重定向到邮件编辑器页面。当我尝试使用它进入邮件编辑器页面时:
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MailEditor(
message: message,
editorType: 'new',
),
),
);
我收到此错误:
[ERROR:flutter/shell/common/shell.cc(213)] Dart 错误:未处理的异常: 使用不包含 Navigator 的上下文请求的 Navigator 操作。 用于从 Navigator 推送或弹出路由的上下文必须是作为 Navigator 小部件后代的小部件的上下文。
这个包是由社区开发的,我在互联网上的任何地方都找不到太多帮助。
我没有在 main.dart 文件之外的任何地方使用 ReceiveSharingIntent 方法,所以也许有一种方法可以直接在我的 mailEditor 页面上使用它,但我没有找到?
如果这里需要更多代码是我的 ReceiveSharingIntent 方法:
class MyApp extends StatefulWidget {
// This widget is the root of your application.
@override
_MssProState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void dispose() {
_intentDataStreamSubscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
// For sharing images coming from outside the app while the app is in the memory
_intentDataStreamSubscription = ReceiveSharingIntent.getMediaStream().listen((List<SharedMediaFile> value) {
_sharedFiles = value;
Message message = Message();
for (var i = 0; i < _sharedFiles.length; i++) {
File file = File(_sharedFiles[i].path);
Attachment attachment = Attachment(
fileName: basename(file.path),
attachmentPart: i + 1,
contentType: lookupMimeType(file.path),
name: basename(file.path),
);
}
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MailEditor(
message: message,
editorType: 'new',
),
),
);
});
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Login(),
routes: {
'/login': (BuildContext context) => Login(),
},
);
}
非常感谢您的任何帮助和建议,我已经坚持了一段时间。
编辑: 为上下文添加了更多代码
【问题讨论】:
标签: flutter android-intent file-sharing