project04 - The fourth knockdown
Stateful and Stateless Widgets in Flutter
This app focuses on describing/making Stateful/Stateless Widgets and making a fresh Dart class by following these steps:
project04 > lib > src > app.dart
class App extends StatelessWidgetWe create a new Dart class named
Appwhich extends (carries properties of)
StatelessWidgetis used when we don't want to save any data in our app. Since, we don't have anything to save right now, therefore we don't use the
Widget build(context)Here we're returning a
Widget, because, this is exactly what Flutter is all about! Also, we're using
StatelessWidget, that's why. Next, we call the
build()method which takes in the
return MaterialAppNow, inside the
MaterialAppwidget, exactly what we coded earlier in main.dart .
project04 > lib > main.dart
runApp(App());We change the
runApp()method and call the
Appclass which's inside the app.dart file making the project modularised.
mainclass will not work as by default Flutter looks into lib folder of the project directory to run the app. Hence, we need to
importthe app.dart class.