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 StatelessWidget
We create a new Dart class namedApp
which extends (carries properties of)StatelessWidget
class. AStatelessWidget
is 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 theStatefulWidget
. -
Widget build(context)
Here we're returning aWidget
, because, this is exactly what Flutter is all about! Also, we're usingStatelessWidget
, that's why. Next, we call thebuild()
method which takes in thecontext
. -
return MaterialApp
Now, inside theWidget
, wereturn
the entireMaterialApp
widget, exactly what we coded earlier in main.dart .
project04 > lib > main.dart
-
runApp(App());
We change therunApp()
method and call theApp
class which's inside the app.dart file making the project modularised. -
import 'src/app.dart';
UsingApp
in themain
class will not work as by default Flutter looks into lib folder of the project directory to run the app. Hence, we need toimport
the app.dart class.