Flutter Getx Routes Constants
Hello everyone,
As part of this project which I intend it to be open-source. I’m developing a mobile application for meditation as part of a cybernetic and holistic project called “Cyberneom”. I’m gonna be sharing and explaining the logic in my repo and the plugins I’m using.
So, I would like to talk about the way I structure my routes with Getx, which was a good solution for me when I was learning flutter and I started using its different features. Thanks Jonataslaw!
The first thing we have to create is a “RouteConstants” class in order to have all our routes in the same file just in case we change any path and for new developers working on the project. NeomRouteConstants would be the case for this constant class. If your project is called as “Tinder”, a good name could be TinderRouteConstants. If its called Vampapp, VampRouteConstants.
class NeomRouteConstants {}
Another thing to do is to be conscious of the domains we are developing, so we can have a wider view of the names hierarchy we have. Something similar as developing microservices with REST Best Practices.
static const String ROOT = "/";
static const String LOGIN = "/login";
static const String FORGOT_PASSWORD = "/forgotPassword";
static const String SIGNUP = "/signup";
static const String LOGOUT = "/logout";
As second phase, we have the routes for the onboarding process which is called “intro” here. If you check the Cyberneom Repo, you are gonna verify the usage, or at least a try lol, of clean architecture with domains and subdomains for the views.
static const String SPLASH_SCREEN = "/splash";
static const String HOME = "/home";
static const String INTRO_LOCALE = "/intro/locale";
static const String INTRO_PROFILE = "/intro/profileType";
static const String INTRO_FREQUENCY = "/intro/frequency";
static const String INTRO_NEOM_REASON = "/intro/neomReason";
static const String INTRO_ADD_IMAGE = "/intro/addImage";
static const String INTRO_CREATING = "/intro/creating";
static const String INTRO_WELCOME = "/intro/welcome";
As part of the main functionality we have the Neom path which would be the main feature of this phase of the app. We can check the processes as “generator” and “analizer”. Also we have the information retrieved or captured in “frequency”, “presets” and the main place as “/chamber” instead of CHAMBERS as the name of the constant. As it’s a best practice have a singular instead of plural.
static const String NEOM_GENERATOR = "/neom/generator";
static const String NEOM_ANALYZER = "/neom/analizer";
static const String FREQUENCIES = "/frequency";
static const String FREQUENCY_FAV = '/frequency/fav';
static const String CHAMBERS = '/chamber';
static const String CHAMBER_PRESETS = '/chamber/presets';
static const String PRESET_DETAILS = '/preset/details';
static const String PRESET_SEARCH = '/preset/search';
For the next scenario you can figure out the views or routes for the profile as self. Something like “My Profile” in Facebook, Instagram or any other social network. Also we have the “neommate” paths which would be the same but for other users.
static const String PROFILE = '/profile';
static const String PROFILE_DETAILS = '/profile/details';
static const String PROFILE_SEARCH = '/profile/search';
static const String NEOMMATES = '/neommate';
static const String NEOMMATE_DETAILS = '/neommate/details';
static const String NEOMMATE_SEARCH = '/neommate/search';
static const String SEARCH = '/search';
static const String INBOX = '/inbox';
static const String INBOX_ROOM = '/inbox/room';
Here, you can find some simple routes for publishing posts, retrieve them to the feed and uploading files.
static const String NEOMPOST = '/neomPost';
static const String NEOMPOST_DETAILS = '/neomPost/details';
static const String NEOM_UPLOAD = '/neomUpload';
static const String NEOM_UPLOAD_2 = '/neomUpload/2';
static const String FEED_ACTIVITY = '/feed/activity';
Finally (by now), we have the information for our Drawer, or side bar, where we usually find information about the app, settings and privacy, user preferences, etc.
static const String PRIVACY_POLICY = '/privacyAndPolicy';
static const String SETTINGS_PRIVACY = '/settingsAndPrivacy';
static const String SETTINGS_ACCOUNT = '/settings/account';
static const String ABOUT = '/about';
static const String ACCOUNT_REMOVE = '/account/remove';
static const String ACCOUNT_SETTINGS = '/account/settings';
static const String PREVIOUS_VERSION = '/previous-version';
static const String UNDER_CONSTRUCTION = '/under-construction';
static const String VERIFY_EMAIL = '/verify/email';
You can find this class at the Cyberneom Repository.
I hope I continue writing articles about my development process and practices I’ve been learning.
Thanks and I’m open to comment as I want to improve my programming.