How to print the current route path in flutter using auto_router? - flutter

I have been using auto_route in my flutter app for navigation. I'm wondering if there's any way to print the current route path (example: /home/profile...). It'll be of great help while debugging and managing the routes.
Is there any way to do it?

It's a very simple implementation, just use this line
print(context.router.currentPath);

By below line you can get curent route:
ModalRoute.of(context).settings.name

Related

Flutter: Localization from API call

I wish to localize a Flutter application where locales are fetched by an API call, given the requested language.
I was hoping to be able to use the Intl package or something similar, but I am not sure this is possible without the .arb files.
Any ideas on how to accomplish this without reinventing the wheel?
(Having the localizations stored locally is not an option)
Down below, you can see a class which is converted to a singleton pattern. You can use any service locator package. It will be the same thing.
Now you can call this class in your main function, default set to EN.
Now let's say, you want to support SPANISH and not want to use .arb files
Now you can call google translate and replace values with the existing one. for every variable. I hope this helps.
Use https://pub.dev/packages/localizely_sdk package, it provides what you want to achieve
Turns out easy_localization has the functionality described. Simply creating a custom HttpAssetLoader and passing it to the easy_localization initialization method works out of the box, and provides device language detection, and application rebuild on locale change as intended.

How to open particular flutter route from kotlin(android) with arguments(custom data)

Hi i want to open a flutter page from kotlin code with custom arguments when app is in terminated state but i dont have any idea how it works. please help regarding this.
Sorry i am still noob.

How to use deep link in flutter web using navigator 2.0 on my webserver?

I can refresh(reload) and deep link when I launch debug in IDE(vscode)
However when I published to own webserver(I made web resource from this command 'flutter web build'), My webserver is intercept my url and return 404.. :(
It can enter from main page only
Webserver is runing on golang and Flutter web using navigator 2.0
How can I solve this?
I can't find reference of flutter navigator 2.0 in web.
Please save my life
The problem because removed hash(#) in url
I was follow this
How to remove hashtag (#) from url in web flutter
but this is cause that problem
When I back to original url(include hash), problem solved.
Please have a look at this code sample that uses new MaterialApp.router() constructor to handle url path.
In the parseRouteInformation of the RouteInformationParser you get the raw url and it's up to you how are you going to interpret the data. For instance, in the above sample the route is converted to object TheAppPath and later handled by RoutePageManager and RouterDelegate.

How to perform Deep-linking with Flutter Web?

Flutter Web: Is there a way to make the URLs for an app appear similar to the navigation route name so that we can do deep linking? For e.g. if I run an app now on chrome, the URL I get is "http://localhost:51322/#/". So if I am on the home screen, how can I have it as "http://localhost:51322/#/home"?
I tried the solution at https://medium.com/flutter-community/more-than-a-flutter-web-app-is-a-full-flutter-website-c6bb210b1f16, but it doesn't seem to work anymore.
The section of the url after the # is the "route name" from "named routes" which are explained pretty well here: https://flutter.dev/docs/cookbook/navigation/named-routes
Specifically to change from "/" to "/home" as your default route, you want to change the "initialRoute" parameter to MaterialApp to "/home" and make sure your routes map has an entry for "/home" instead of "/"
There are a few ways to tell MaterialApp what the "home" or "root" Widget is, you will want to be careful that you don't give it conflicting instructions. The specifics are in the class documentation: https://api.flutter.dev/flutter/material/MaterialApp-class.html

Flutter Navigator default route route in Fluro package

I am using Flutter with Fluro package and I want to set a default route for the app.
The need is to have a place to decide which path the user needs to navigate to, and from there to navigate the app by whatever settings decided upon.
Currently, I defined the routes in the app and do have a "404" (not found) route as described in the docs of the package, but I prefer to have another way which is more correct to solve it.
For example, the app has the routes:
"homepage"
"splash_screen"
"search"
"not_found"
"init"
I want the route init to be the default one.
Thank you,
Nisim
After digging some more I found the Fluro package has internal class RouteTree which handles all routes. when adding a new route it will check if it defaults by comparing it to Navigator.defaultRouteName (value "/").
Note: it allow you to add only one default route and will throw an exception if you do it more then one.
Adding the default route with handler solved the issue and now the default route is the one deciding about the next route and displays something in the meantime.