Creating New Screen¶
Follow these steps to create new screens in your Flutter project:
-
[Optional but good to have] Make sure you have a
screensfolder in yourlibfolder -
Create a new file in the
screensfolder -
Name the file something and end with
_screen.dart, for examplelogin_screen.dart(feel free to rename it) -
Open the newly created Dart file
-
Import
material.dart: -
Create the class and the class name should be in
PascalCaseand extend eitherStatelessWidgetorStatefulWidgetTIP
It is better to create as a
StatelessWidgetfirst and then later convert it into aStatefulWidget. -
In the class, always remember to add the
routeNamefor the screen and the value will start with/: -
After creating the
routeName, you will need to add thebuild()method and do not forget to add@override: -
In the
build()method, normally a screen will haveScaffoldas the base for the screen:NOTE
If there is a
tabin the screen, you will haveDefaultTabControllerwrapped around theScaffoldfirst. -
Save your changes
-
Go to the
main.dartfile and "register" the route under theroutesinside theMaterialAppproperties: