In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how Flutter routing framework Fluro is used. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
In the process of Flutter application development, in addition to using the routes provided by Flutter official, you can also use some third-party routing frameworks to implement page management and navigation, such as Fluro, Frouter, etc.
Fluro is an excellent Flutter enterprise routing framework. Fluro is more complex to use than the official routing framework, but it is very suitable for medium and large projects. Because it has the advantages of clear hierarchy, organization, convenient expansion and overall management routing.
Before using Fluro, you need to add Fluro dependencies to the pubspec.yaml file, as shown below.
dependencies: fluro: "^1.5.1"
If you cannot add Fluro dependencies using the above method, you can also add Fluro dependencies using git, as shown below.
dependencies: fluro: git: git://github.com/theyakka/fluro.git
After successfully adding Fluro library dependencies, you can use Fluro for application routing management and navigation development. In order to manage routes uniformly, you need to create a route mapping file to manage each route. The following is sample code for the routing profile route_handles.dart.
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';//empty page var emptyHandler = new Handler ( handlerFunc: (BuildContext context, Map params) { return PageEmpty(); });//A Page var aHandler = new Handler ( handlerFunc: (BuildContext context, Map params) { return PageA(); });//B page var bHandler = new Handler ( handlerFunc: (BuildContext context, Map params) { return PageB(); });
After completing the basic routing configuration, we also need a static overall routing configuration file, which we can use in the routing page. The following is sample code for the routing profile routes.dart.
import 'package:fluro/fluro.dart'; import 'package:flutter_demo/route_handles.dart';class Routes { static String page_a = "/"; //Note 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; //Empty page}}
When doing the overall configuration of routes, you also need to deal with non-existent path cases, i.e., replace them with empty pages or default pages. At the same time, it should be noted that the home page of the application must be configured with "/". For ease of use, you also need to make Router static, so that it can be called directly from any page. The following is sample code for the application.dart file.
import 'package:fluro/fluro.dart';class Application{ static Router router;}
After completing the above operations, you can introduce routing configuration files and static files into the main.dart file, 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 the Application.router.navigateTo() method, as shown below.
Application.router.navigateTo(context,"/b"); //b is the configuration route
It can be found that although Fluro is more cumbersome to use than Flutter's Navigator, it is very suitable for medium and large projects. Its layered architecture is also very convenient for upgrading and maintenance in the later stages of the project.
Thank you for reading! About "Flutter routing framework Fluro how to use" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.