• flutter-路由


    1.新建1个页面 details_page.dart

    2.引入  fluro: "^1.6.3"

    3.在lib文件夹下新建文件夹router,然后新建router_handler.dart

    import 'package:flutter/material.dart';
    import 'package:fluro/fluro.dart';
    import '../pages/details_page.dart';
    
    var detailsHandler=Handler(
      handlerFunc: (BuildContext context,Map<String, dynamic> params){
        String goodsId=params['id'].first;
        return DetailsPage(goodsId);
      }
    );

    4.新建文件routes.dart

    import 'package:flutter/material.dart';
    import 'package:fluro/fluro.dart';
    import './router_handler.dart';
    
    class Routes{
      static String root='/';
      static String detailsPage='/detail';
      static void configureRoutes(Router router){
        router.notFoundHandler=new Handler(//找不到路由
          handlerFunc:(BuildContext context,Map<String, dynamic> params){
            print('Error===>ROUTE WAS NOT FOUND!!!!');
          }
        );
        router.define(detailsPage, handler: detailsHandler);//配置地址路由
      }
    }

    5.新建application.dart 方便以后不引入 不用new了

    import 'package:fluro/fluro.dart';
    
    class Application{
      static Router router;
    }

    6.main.dart

    import 'package:fluro/fluro.dart';

    import './router/application.dart';
    import './router/routes.dart';
    //在build中引入
    final router=Router();
    Routes.configureRoutes(router);
    Application.router=router;

     7.使用

    import '../router/application.dart';
  • 相关阅读:
    常见的HTTP状态码(HTTP Status Code)说明
    Java基本数据类型和Integer缓存机制
    面向对象的三大基本特征和五大基本原则
    工程变更(ENGINEERING CHANGE)
    反射
    Redis学习手册(开篇)
    MVC,SSM与三层架构的构成及相互关系
    Java框架篇---Mybatis 入门
    java三大框架介绍
    WEB前端JS与UI框架
  • 原文地址:https://www.cnblogs.com/lxz-blogs/p/13305484.html
Copyright © 2020-2023  润新知