zoukankan      html  css  js  c++  java
  • 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
    等找到了就补上

  • 相关阅读:
    JAVA基础:JAVA代码编写的30条建议
    Oracle学习之三 程序控制结构
    ExtJs 常用代码片段(7.30更新)
    ExtJs4 之数据模型
    .NET 大杂烩
    .NET 导出Excel
    Javascript实现IE直接打印
    C# Timer用法及实例
    AjaxPro实现无刷新多级联动实例
    VB6.0输入文本写进UTF8格式的文本文件
  • 原文地址:https://www.cnblogs.com/gggggggxin/p/10484506.html
Copyright © 2011-2022 走看看