jonataslaw
Committed by GitHub

Update README.md

Showing 1 changed file with 24 additions and 4 deletions
@@ -54,7 +54,8 @@ Get.offAll(NextScreen()); @@ -54,7 +54,8 @@ Get.offAll(NextScreen());
54 54
55 Is possible used default namedRoutes from flutter? 55 Is possible used default namedRoutes from flutter?
56 Yes, and with no navigation bug 56 Yes, and with no navigation bug
57 -Example: 57 +
  58 +### Add " navigatorKey: Get.key," to MaterialApp
58 59
59 ```dart 60 ```dart
60 void main() { 61 void main() {
@@ -65,16 +66,30 @@ void main() { @@ -65,16 +66,30 @@ void main() {
65 title: 'Navigation', 66 title: 'Navigation',
66 )); 67 ));
67 } 68 }
  69 +```
  70 +
  71 +Copy this class and put it in your app, rename routes and classes for your own, add more classes to it if necessary.
  72 +### Important!!! We suggest that you copy this class for 3 reasons:
  73 +1- You must define an escape route if you accidentally set a wrong route. This example already contains this.
  74 +Flutter_Web does not provide friendly urls or url settings (no matter how you set the route, it will always return to the main page after the page is reloaded and the route is not displayed in the url with default navigation) But Get supports it! So, when a user enters yourflutterwebsite.com/support and exactly the support route is displayed, you need to pass the settings parameter to GetRoute, and this example already contemplates it!
  75 +3- These routes are designed to work with GetRoute, not CupertinoPageRoute or MaterialPageRoute. Never put them here.
68 76
  77 +```dart
69 class Router { 78 class Router {
70 static Route<dynamic> generateRoute(RouteSettings settings) { 79 static Route<dynamic> generateRoute(RouteSettings settings) {
71 switch (settings.name) { 80 switch (settings.name) {
72 case '/': 81 case '/':
73 - return GetRoute(builder: (_) => FirstRoute());  
74 - case '/second':  
75 - return GetRoute(builder: (_) => SecondRoute()); 82 + return GetRoute(
  83 + builder: (_) => SplashScreen(),
  84 + settings: settings,
  85 + );
  86 + case '/Home':
  87 + return GetRoute(settings: settings, builder: (_) => Home());
  88 + case '/Chat':
  89 + return GetRoute(settings: settings, builder: (_) => Chat());
76 default: 90 default:
77 return GetRoute( 91 return GetRoute(
  92 + settings: settings,
78 builder: (_) => Scaffold( 93 builder: (_) => Scaffold(
79 body: Center( 94 body: Center(
80 child: Text('No route defined for ${settings.name}')), 95 child: Text('No route defined for ${settings.name}')),
@@ -82,7 +97,10 @@ class Router { @@ -82,7 +97,10 @@ class Router {
82 } 97 }
83 } 98 }
84 } 99 }
  100 +```
  101 +And now, all you need to do is use Get.toNamed() to navigate your named routes, without any context (BLoC will love it), and when your app is compiled to the web, your routes will appear in the url beautifully <3
85 102
  103 +```dart
86 class FirstRoute extends StatelessWidget { 104 class FirstRoute extends StatelessWidget {
87 @override 105 @override
88 Widget build(BuildContext context) { 106 Widget build(BuildContext context) {
@@ -121,3 +139,5 @@ class SecondRoute extends StatelessWidget { @@ -121,3 +139,5 @@ class SecondRoute extends StatelessWidget {
121 } 139 }
122 } 140 }
123 ``` 141 ```
  142 +
  143 +That is all.