fluro_support
Quick to use Fluro
Getting Started
You should ensure that you add the router as a dependency in your flutter project.
代码语言:javascript复制dependencies:
fluro_support:
git: https://github.com/OSpoon/fluro_support.git
Setting up
初始化 FSRoutes
代码语言:javascript复制import 'package:fluro_support/fluro_support.dart';
import 'package:fluro/fluro.dart';
//定义路由集合
List<FSBaseRouter> routes = [ModelRoutes()];
//构造函数中初始化
MyApp() {
FSRoutes.init(Router(), routes);
}
return MaterialApp(
//生成路由
onGenerateRoute: FSRoutes.generator(),
);
构建 ModelRoutes
代码语言:javascript复制import 'package:fluro/fluro.dart';
import 'package:fluro_support/fluro_support.dart';
import 'package:flutter/material.dart';
class ModelRoutes extends FSBaseRouter {
static String otherPage = "/other";
@override
void initRouter(Router router) {
router.define(otherPage, handler: Handler(handlerFunc:
(BuildContext context, Map<String, List<String>> parameters) {
print('${parameters['name']}');
print('${parameters['email']}');
print('${parameters['counter']}');
return OtherPage(
name: parameters['name'][0],
email: parameters['email'][0],
counter: parameters['counter'][0],
);
}));
}
}
Navigating
打开新的页面
代码语言:javascript复制FSNavigate.push(context, LoginModelRouter.loginPage);
打开新的页面(携带参数,接收返回)
代码语言:javascript复制FSNavigate.pushResult(context,
'${ModelRoutes.otherPage}?name=${Uri.encodeComponent(name)}&email=${Uri.encodeComponent(email)}&counter=${Uri.encodeComponent(_counter.toString())}',
(result) {
setState(() {
print('_MyHomePageState._incrementCounter :::${result}');
});
});
直接返回
代码语言:javascript复制FSNavigate.goBack(context);
带参数返回
代码语言:javascript复制FSNavigate.goBackWithParams(context, "sanjin");