flutter - fluro

路由传参

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 {
    Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
                        backgroundColor: Color(constant.mainColor),
                        title: Text(widget._result)
                        ),
            body:Text(widget._result)
                    )
            }
}

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

转载于:https://www.cnblogs.com/gggggggxin/p/10484506.html

你可能感兴趣的:(flutter - fluro)