包装Fluro之fluro_support

2022-12-24 10:47:45 浏览数 (1)

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");
代码参考简书-練碩

0 人点赞