Flutter完全开发手册
  • Flutter 普通路由、普通路由页面跳转传值

    在flutter中路由也是用来处理页面跳转、页面数据传递等操作,主要是通过路由(Route)和导航器(Navigator)来配合实现。

    Navigator.of(context) .push() 页面跳转

    Navigator.of(context).pop(); 返回上一页

    Flutter 中给我们提供了两种配置路由跳转的方式 1.基本路由 2.命名路由

    自学之路Flutter普通路由页面跳转传值

    一、Flutter中的基本路由

    比如我们现在想从HomePage页面跳转到 SearchPage页面

    1、需要在HomePage中引入SearchPage.dart

    2、在HomePage中通过navigator.of(context).push()跳转。

    
    //跳转路由
    Navigator.of(context) .push(  //页面跳转
    	MaterialPageRoute(  //基本跳转
    	builder: (BuildContext context) {
    	return const SearchPage();  //跳转页面
    }));
    

    Navigator.of(context).push() //属于基本路由跳转。

    通过push参数需要一个MaterialPageRoute对象。

    二、Flutter 中的基本路由跳转传值

    需求:从 HomePage 页面跳转到 CategoryPage 页面

    1、在CategoryPage 页面定义参数 接收传值

    2、跳转页面实现传值

    
    Navigator.of(context).push(
       MaterialPageRoute(builder: (BuildContext context) { 
       return const CategoryPage(title: "男士西装",id: 12,); // 传值
    })
    );