如何解决Flutter接收共享意图和页面更改
我正在开发邮件应用程序,当我尝试共享文件以通过receive_sharing_intent package通过电子邮件发送文件时被卡住了
我能够在应用程序中获取文件及其路径和所有内容,但是随后我需要将用户重定向到邮件编辑器页面。当我尝试使用它进入mailEditor页面时:
Navigator.push(
context,MaterialPageRoute(
builder: (context) => MailEditor(
message: message,editorType: 'new',),);
我收到此错误:
[错误:Flutter / shell / common / shell.cc(213)] Dart错误:未处理的异常: 请求的导航器操作使用了不包含导航器的上下文。 用于从导航器推送或弹出路由的上下文必须是作为导航器小部件的后代的小部件的上下文。
此软件包是由社区开发的,我在Internet上找不到任何帮助。
除了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,);
});
return MaterialApp(
debugShowCheckedModeBanner: false,home: Login(),routes: {
'/login': (BuildContext context) => Login(),},);
}
非常感谢您的帮助和建议,我已经坚持了一段时间。
解决方法
导航器应在build()
方法内使用。如果要在其外部使用context
,请将其作为参数传递,例如BuildContext context
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。