• flutter


    路由传参

    route.dart

    import 'package:fluro/fluro.dart';
    //添加页面
    import 'package:m/pages/loginPage.dart';
    import 'package:m/pages/homePage.dart';
    import 'package:m/pages/searchPage.dart';
    
    class Routes {
      static Router router;
      static void configureRoutes(Router router) {
    //登陆页
        router.define('/', handler: new Handler(handlerFunc: (context, params) {
          return new LoginPage();
        }));
    //主页
        router.define('/home', handler: new Handler(handlerFunc: (context, params) {
          return new HomePage();
        }));
    //搜索页
        router.define('/search/:data', handler: new Handler(handlerFunc: (context, params) {
          return SearchPage(params['data'][0]);
        }));
        Routes.router = router;
      }
    }
    

    配置 main.dart

    import 'package:flutter/material.dart';
    import 'package:fluro/fluro.dart';
    
    void main() {
      ///初始化并配置路由
      final router = new Router();
      Routes.configureRoutes(router);
      return runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(onGenerateRoute: Routes.router.generator);
      }
    }
    
    

    login跳转home ,不带参数

    import 'package:flutter/material.dart';
    import 'package:fluro/fluro.dart';
    
    //跳转主页
    Routes.router.navigateTo(context, '/home', //跳转路径
        transition: TransitionType.inFromRight //过场效果
    );
    

    跳转search,带参数
    home.dart

    //home.dart
    var kind = 'ssss';
    Routes.router.navigateTo(
        context, '/search/$kind', //跳转路径
        transition: TransitionType.fadeIn //过场效果
    );
    
    

    search.dart

    //search.dart
    class SearchPage extends StatefulWidget {
    //接受传值
        String _result;
        SearchPage(this._result);
    
    @override
    _SearchPageState createState() => _SearchPageState();
    }
    
    class _SearchPageState extends State<SearchPage> {
        Widget build(BuildContext context) {
            return Scaffold(
                appBar: AppBar(
                            backgroundColor: Color(constant.mainColor),
                            title: Text(widget._result)
                            ),
                body:Text(widget._result)
                        )
                }
    }
    

    ps:找不到pop传参的。难受。只能用之前的navigator.pop
    等找到了就补上

  • 相关阅读:
    JavaScript二(第一个js程序)
    JavaScript简述一
    选择合适的Linux版本
    jQuery(一)引入
    Java从零开始学零(Java简介)
    正则表达式
    通过Servlet生成验证码图片(转)
    监听器(web基础学习笔记二十二)
    利用Session完成用户的登录和注销
    Spring Security OAuth 2.0
  • 原文地址:https://www.cnblogs.com/gggggggxin/p/10484506.html
Copyright © 2020-2023  润新知