美文网首页
flutter 命名路由传参

flutter 命名路由传参

作者: neobuger | 来源:发表于2022-09-29 18:01 被阅读0次

    需要展示的页面

    class BreachDetailVC extends StatefulWidget {
      String breachApplyId = "";
    
      BreachDetailVC({Key? key}) : super(key: key);
      BreachDetailVC.needId({Key? key, required this.breachApplyId}) : super(key: key);
    
      @override
      State<BreachDetailVC> createState() => _BreachDetailVCState();
    }
    
    class _BreachDetailVCState extends State<BreachDetailVC> {
        @override
    //在 initState写 获取参数的代码会报错
    //breachApplyId是传入的参数
      void didChangeDependencies() {
        super.didChangeDependencies();
    
        RouteSettings sttings =  ModalRoute.of(context)!.settings!;
        var args=sttings!.arguments;
        Map params = args as Map;
        this.widget.breachApplyId = params["breachApplyId"];
        print(args);
        print("breachApplyId" + this.widget.breachApplyId);
    
        queryData();
      }
    }
    
    

    //路由配置

    class MyBreahRouteGenerator {
      static final routes = {
        "/breachList/detail":(context) => BreachDetailVC(),
    //    "/breachList/detail":(context, {arguments}) => BreachDetailVC(),
    
      };
    }
    

    //跳转代码

    Navigator.pushNamed(context, '/breachList/detail', arguments: {
         "breachApplyId" : this.widget.model["breachApplyId"]
       });
    

    相关文章

      网友评论

          本文标题:flutter 命名路由传参

          本文链接:https://www.haomeiwen.com/subject/gqukartx.html