Creating New Widget¶
Follow these steps to create new widgets in your Flutter project:
-
[Optional but good to have] Make sure you have a
widgets
folder in yourlib
folder -
Create a new file in the
widgets
folder -
Name the file something ending with
_widget.dart
, for exampleform_widget.dart
(feel free to rename it) -
Open the newly created Dart file
-
Import
material.dart
: -
Create the class in
PascalCase
and extend eitherStatelessWidget
orStatefulWidget
TIP
It is better to create it as a
StatelessWidget
first and then convert it into aStatefulWidget
if needed. -
In the
class
, add thebuild()
method and do not forget to add@override
:REMEMBER
routeName
is not needed for a widget! -
In the
build()
method, return the type of widget you want to use: -
Save your changes
REMEMBER
Since there is no
routeName
in a widget, you do not need to "register" routes.