सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
vRouter एक ऐसा नेविगेशन पैकेज है जो फ्लटर के लिए सभी प्लेटफ़ॉर्मों पर रूटिंग और नेविगेशन को सरल बनाता है। नेविगेटर 2 के ऊपर बनाया गया, यह एक घोषणात्मक और प्रकार-सुरक्षित तरीके से एप्प नेविगेशन को प्रबंधित करता है, जिसमें नेस्टेड रूट्स, डीप लिंकिंग और डायनामिक रूट हैंडलिंग शामिल है। यह बॉइलरप्लेट को कम करके और रूट प्रबंधन की विस्तारशीलता में सुधार करके डेवलपर अनुभव को बढ़ाता है। यह पैकेज प्लेटफ़ॉर्म-अनिर्भर रूटिंग तर्क को समर्थन देता है, जिससे यह एक समान नेविगेशन व्यवहार की आवश्यकता वाले जटिल एप्प्स के लिए उपयुक्त है।
उपयोग
नेस्टेड नेविगेशन के साथ सिंगल-पेज एप्लिकेशन
एकीकृत रूटिंग की आवश्यकता वाले क्रॉस-प्लेटफॉर्म एप्लिकेशन
गहन लिंकिंग समर्थन की आवश्यकता वाले ऐप
गतिशील सेगमेंट वाले जटिल मार्ग पदानुक्रम
नेविगेशन फ्लो में सरल राज्य प्रबंधन
मुख्य विशेषताएँ
घोषित मार्ग संरचना
नेस्टेड और डायनामिक रूट का समर्थन
आधुनिक रूटिंग के लिए नेविगेटर 2 पर आधारित
प्लेटफॉर्म-अनुकूल नेविगेशन तर्क
प्रकार सुरक्षित मार्ग परिभाषाएँ
मौजूदा Flutter ऐप्स के साथ आसान एकीकरण
इनके लिए उपयुक्त
स्केलेबल फ्लटर एप्प्स बनाने वाले डेवलपर्स
जटिल नेविगेशन संरचना का प्रबंधन करने वाली टीमें
गहरे लिंकिंग और URL संभालने की आवश्यकता वाले प्रोजेक्ट
एक समान रूटिंग के साथ कई प्लेटफॉर्म के लिए लक्षित ऐप्स
स्पष्ट, अधिक रखरखाव नेविगेशन कोड चाहने वाले डेवलपर्स
विचार योग्य बातें
Navigator 2 के अवधारणाओं को समझने की आवश्यकता है
उन्नत उपयोग के मामलों के लिए अतिरिक्त सेटअप की आवश्यकता हो सकती है
मुख्यधारा पैकेज की तुलना में सीमित डॉक्यूमेंटेशन
संरचित नेविगेशन की आवश्यकता वाले ऐप्स के लिए सबसे उपयुक्त
मूल README
संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।
A Flutter package that makes navigation and routing easy.
VRouter is a widget which handles the navigation, it acts as a MaterialApp but also takes a routes arguments.
VRouter(
debugShowCheckedModeBanner: false, // VRouter acts as a MaterialApp
routes: [...], // Put your VRouteElements here
)
VRouteElements
VRouteElements are the building blocs of your routes.
Note that they are not widgets but the way you use them is very similar to widgets.
VWidget
VWidget maps a path to a widget:
VWidget(path: '/login', widget: LoginScreen())
VGuard
VGuard allows you to take actions when the route is accessed/leaved:
VGuard(
beforeEnter: (vRedirector) async => , // Triggered when a route in stackedRoutes is first displayed
beforeUpdate: (vRedirector) async => , // Triggered when a route in stackedRoutes is displayed but changes
beforeLeave: (vRedirector, _) async => , // Triggered when VGuard is not part of a new route
stackedRoutes: [...],
);
VRouteRedirector
VRouteRedirector redirects from a route to another:
VNester are used when you need to nested widgets instead of stacking them:
VNester(
path: '/home',
widgetBuilder: (child) => MyScaffold(body: child), // child will take the value of the widget in nestedRoutes
nestedRoutes: [
VWidget(path: 'profile', widget: ProfileScreen()), // path '/home/profile'VWidget(path: 'settings', widget: SettingsScreen()), // path '/home/settings'
],
)
VPopHandler
VPopHandler helps you control pop events:
VPopHandler(
onPop: (vRedirector) async =>, // Called when this VRouteElement is popped
onSystemPop: (vRedirector) async =>, // Called when this VRouteElement is popped by android back button
stackedRoutes: [...],
)
Navigation
Navigating is easy, just access VRouter with context.vRouter and navigate:
context.vRouter.to('/home'); // Push the url '/home'
context.vRouter.toSegments(['home', 'settings']); // Push the url '/home/settings'
Useful notions
Composition
VRouteElements are designed like widgets: compose them to create the route you need.
Compose VRouteElements
To compose VRouteElements, use the stackedRoutes attribute (or the nestedRoutes attribute for VNester):
// Composing a VGuard and a VWidgetVGuard(
beforeEnter: (vRedirector) async => !isLoggedIn ? vRedirector.to('/login') : null,
stackedRoutes: [
VWidget(path: '/home', widget: HomeScreen()),
],
)
Create custom VRouteElements
You can even create your own VRouteElement, as you extend VWidget. You just need to extends VRouteElementBuilder:
VRouter contains data (such as the path or path parameters) that you might want to access in your widget tree. There are 2 ways of doing do:
// Use the context
context.vRouter
// Use the builder constructor of some VWidget or VNesterVWidget.builder(
path: '/:id',
builder: (context, state) => Book(id: state.pathParameters['id'] asint),
)
Go Beyond
We have just scratched the surface of what VRouter can do. Here are a few other things which you might like.
Initial url
Maybe you want to redirect people to a certain part of your app when they first launch it, then use initialUrl:
VRouter(
initialUrl: '/home',
routes: [...],
)
Logs
By default, VRouter shows logs of every navigation events.
You can remove these logs using VLogs.none:
VRouter(
logs: VLogs.none,
routes: [...],
);
Named route
You might have to access a deeply nested VRouteElement and don’t want to have to write the full url. Just give a name to this VRouteElement:
You can either specify a default transition in VRouter, or a custom one in VWidget or VNester
VRouter(
// Default transition
buildTransition: (animation1, _, child) => FadeTransition(opacity: animation1, child: child),
routes: [
// The custom ScaleTransition will play for '/user'VWidget(
path: '/user',
widget: UsersScreen(),
buildTransition: (animation1, _, child) => ScaleTransition(scale: animation1, child: child),
)
// The default FadeTransition will play for '/settings'VWidget(path: '/settings', widget: SettingsScreen()),
],
)
Much more
There is so much more that this package can do, check out the example
or have a look at the vrouter.dev website for more documentation and more examples.