Creating New Screen¶
Follow these steps to create new screens in your Flutter project:
-
[Optional but good to have] Make sure you have a
screens
folder in yourlib
folder -
Create a new file in the
screens
folder -
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
PascalCase
and extend eitherStatelessWidget
orStatefulWidget
TIP
It is better to create as a
StatelessWidget
first and then later convert it into aStatefulWidget
. -
In the class, always remember to add the
routeName
for 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 haveScaffold
as the base for the screen:NOTE
If there is a
tab
in the screen, you will haveDefaultTabController
wrapped around theScaffold
first. -
Save your changes
-
Go to the
main.dart
file and "register" the route under theroutes
inside theMaterialApp
properties: