Creating New Widget¶
Follow these steps to create new widgets in your Flutter project:
-
[Optional but good to have] Make sure you have a
widgetsfolder in yourlibfolder -
Create a new file in the
widgetsfolder -
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
PascalCaseand extend eitherStatelessWidgetorStatefulWidgetTIP
It is better to create it as a
StatelessWidgetfirst and then convert it into aStatefulWidgetif needed. -
In the
class, add thebuild()method and do not forget to add@override:REMEMBER
routeNameis 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
routeNamein a widget, you do not need to "register" routes.