因此,我的lab_widget有一个普通按钮,它从另一个文件not_plugin调用函数。我希望每次单击按钮时,not_pugin中的函数打开一个确定的屏幕。这是我在not_plugin中所拥有的:
Future<dynamic> onClick(String payload) async {
//Do other things
Navigator.push(context, MaterialPageRoute(builder: (context) => LabMdScreen()));
}
但这会引发以下错误:
46:24:错误:未为类“ NotPlugin”定义吸气剂“上下文”。
- “ NotPlugin”来自“ not_plugin.dart”。尝试将名称更正为现有吸气剂的名称,或定义一个名为“ context”的吸气剂或字段。Navigator.push(上下文,MaterialPageRoute(builder:(上下文)=> MyScreen()));
那么我该如何解决呢?
更新
传递BuildContext后,在另一个函数中引发此错误:
Future<void> initLocalNotification() async {
androidInitializationSettings =
AndroidInitializationSettings('@mipmap/ic_launcher');//here
iosInitializationSettings = IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
initializationSettings = InitializationSettings(
android: androidInitializationSettings, iOS: iosInitializationSettings);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onClick());
}
在最后一行(onSelectNotification:onClick());)
错误:无法将参数类型'Future'分配给参数类型'Future Function(String)'
您需要将BuildContext传递给函数:
void onClick(String payload, BuildContext context) {
//Do other things
Navigator.push(context, MaterialPageRoute(builder: (context) => LabMdScreen()));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句