正在获取与控制器中的pushnamed参数一起发送的参数


Navigator.pushNamed(context, QuestionScreen.routeName,
arguments: paper);

我正在向问题屏幕发送数据,但我想先在问题控制器中获取数据。对于状态管理,我使用riverpod和provider,并用于路由ongenerateroute。

class QuestionsController {}

如何在QuestionsController中获取参数?

您可以使用ModalRoute.of(context)?.settings.arguments;来获取参数。

class QuestionScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final args = ModalRoute.of(context)?.settings.arguments; // use as with nullable if needed 
if (args != null) {
print(args);
}
return Container();
}
}

最新更新