Dart&Flutter-在屏幕之间传递数据。 NoSuchMethodError由MaterialPageRoute()中的小部件引起

时间:2020-05-01 21:06:30

标签: flutter dart parameters nosuchmethoderror

我尝试将数据从过滤器页面传递到主页,但始终出现以下错误。 控制台上的错误消息-NoSuchMethodError由MaterialPageRoute()中的窗口小部件引起

//Radio button values to select user's gender on Filter Page
enum PrayditatorGender { Female, Male }
PrayditatorGender pGender;

//Radio button values to select Prayditation category on Filter Page
enum PrayditationFilter {
  All,
  Family,
  Fellowship,
  GodlyWisdom,
  GoodSuccess,
  HealthAndSafety,
}
PrayditationFilter pFilter = PrayditationFilter.All;


    //Code to push the data from Filter Page to Home Page
    Navigator.push(context, MaterialPageRoute(
         builder: (context) {
             PrayditatorHomePage(
              pGender: pGender,
              pFilter: pFilter
              )
    ));




    //Code to handle the data on Home Page
    class PrayditatorHomePage extends StatefulWidget {
      final PrayditatorGender pGender;
      final PrayditationFilter pFilter;
      PrayditatorHomePage({this.pGender, this.pFilter});

      @override
      _PrayditatorHomePageState createState() => _PrayditatorHomePageState();
    }

    class _PrayditatorHomePageState extends State<PrayditatorHomePage> {
      @override
      Widget build(BuildContext context) {}

2 个答案:

答案 0 :(得分:0)

您的语法错误,您不应该遇到此问题,此代码可以正常工作:

Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => PrayditatorHomePage(
          pGender: pGender,
          pFilter: pFilter,
        ),
      ),
    );

答案 1 :(得分:0)

感谢大家花时间查看/评论。错误已消除,代码有效运行!

语法完全正确,但是,将静态参数不适当地放置在用于动态参数的位置。毕竟,经验教训。