How to use the routing framework Fluro? Flutter this framework so good!

Flutter in the application development process, in addition to using the route Flutter official offer, you can also use some third-party routing and management framework to implement page navigation, such as Fluro, Frouter and so on.

Fluro as a good Flutter enterprise-class routing framework, Fluro to use than routing framework provided by the official more complicated, but it is very suitable for large-scale projects. Because it has a distinct, well-organized to facilitate the expansion and facilitate the overall management of the routing and other advantages.

Then how do we use this excellent framework it? follow me

There BATJ, byte beating interview topics, topics algorithms, high-end technology topics, mixed-use development themes, java interview topics, Android, Java little knowledge, to performance optimization. .View.OpenCV.NDK thread, etc. have been uploaded to my GitHub

My GitHub learn Address:https://github.com/Meng997998/AndroidJX learn together under the star point

Fluro in dependence need to add before use Fluro pubspec.yaml file, as shown below.

dependencies:
 fluro: "^1.5.1"

If you can not rely on the use Fluro added the above manner, may also be used in the Add Fluro git dependent, as shown below.

dependencies:
 fluro:
   git: git://github.com/theyakka/fluro.git

After successfully added Fluro library dependencies, you can use Fluro be applied routing management and navigation developed. In order to facilitate unified management of routing, you first need to create a new route map file, used to manage each route. As shown below, it is an example of the code route_handles.dart route profile.

import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/page_a.dart';
import 'package:flutter_demo/page_b.dart';
import 'package:flutter_demo/page_empty.dart';

//空页面
var emptyHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      return PageEmpty();
    });

//A页面
var aHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return PageA();
    });

//B页面
var bHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return PageB();
    });

After completing the basic routing configuration, but also a general static routing configuration files to help us in routing page. As shown below, it is an example of code for routing the overall profile routes.dart.

import 'package:fluro/fluro.dart';
import 'package:flutter_demo/route_handles.dart';

class Routes {
  static String page_a = "/";                   //需要注意
  static String page_b = "/b";

  static void configureRoutes(Router router) {
    router.define(page_a, handler: aHandler);
    router.define(page_b, handler: bHandler);
    router.notFoundHandler =emptyHandler;     //空页面
  }
}

When performing the overall configuration of the route, but also the absence of the processing path, i.e. an empty page or pages instead of the default. At the same time, it is noted that the application of the home must use "/" configuration.
For ease of use, Router also need to be static, so that any page can call it directly. As shown below, it is an example of the code application.dart file.

import 'package:fluro/fluro.dart';

class Application{
  static Router router;
}

After the completion of the operation, it can be incorporated in the route profile file main.dart and static files, as shown below.

import 'package:fluro/fluro.dart';
import 'package:flutter_demo/routes.dart';

import 'application.dart';

void main() {
  Router router = Router();
  Routes.configureRoutes(router);
  Application.router = router;

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Demo App',
      onGenerateRoute: Application.router.generator,
    );
  }
}

If you want to jump to a page, just use Application.router.navigateTo () method, as shown below.

Application.router.navigateTo(context,"/b"); //b为配置路由

Running sample code above, results as shown in FIG.
How to use the routing framework Fluro?  Flutter this framework so good!

Can be found, Fluro although cumbersome to use compared Navigator Flutter, but for the large-scale projects is very fit, it's layered architecture is also very easy to upgrade and maintain the latter part of the project, can be a reasonable choice according to the actual situation of use.

In the world, Flutter is being used by a growing number of developers and organizations, Flutter totally free, open source, as Google now own son, it is worth learning!

If you do not want to fall behind, I can share my learning Flutter of video

This video includes entry to the real, very practical, there are major Internet companies love Flutter mixed-use development, enterprise integration projects essential to Native SDK explanations, and from white to grow into large cattle Flutter the only way to develop plug-ins , as well as more advanced Flutter explain the project and so optimized content.

Now free for everyone to share together, you can leave comments area, I can whisper

Do not hesitate, I'm concerned, together into the world Flutter it!

How to use the routing framework Fluro?  Flutter this framework so good!

Guess you like

Origin blog.51cto.com/14606040/2467601