By WalkingTree   June 19, 2020

The Main Function in Flutter

Most of the time when we start a new Flutter project there’s this single line of code that we don’t have to change. That code starts the Flutter app and makes sure to show it to the user.

The main function will run the MyApp() constructor, like any other programming language where the main function is the entry point to start an application. Although this function runs perfectly, we may come across some issues in projects which are more complex:

  • The command will only run the MyApp widget without any arguments, but what if you want a completely different backend environment to be called, or what if there are other versions of the app which you want to test and deploy? 
  • What to do if you want to check the user preferences like theme, language, etc. before the application runs? Or how to check whether the user has logged in or not, in order to show the correct screen?
  • Lastly, what if there’s an error in the application? How to show the error screen to the user for reporting the error?

Let’s take a look at the main function and possible solutions for the above questions.

Managing different app versions – There are many reasons to have different versions of an application, from different backend environments to different branding. Whatever the case might be, you will have to instruct Flutter on what to display or change in the app without creating separate projects for each app. You can build Flutter apps via the $ flutter run command. But how will MyApp widget know that you are running different versions? The way is to create a configuration for each file with a config data class. 

Read on to progress on this topic.

Flutter Blogs

Theming in Flutter

Theming is styling an application so that its look and feel matches your personal design aesthetic or that…

Translate »
Privacy Preferences
When you visit our website, it may store information through your browser from specific services, usually in form of cookies. Here you can change your privacy preferences. Please note that blocking some types of cookies may impact your experience on our website and the services we offer.