Start off by creating a brand new flutter project called flutter_layout, either via your IDE or the command line. Don't worry about the sample code generated. We're going to delete it and start from scratch:
- Open main.dart and delete everything! Then, type the following code into the editor:
void main() => runApp(StaticApp());
class StaticApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: ImmutableWidget(),
);
}
}
-
Notice that you have a bunch of red underlines. We need to fix this by importing the material.dart library. This can be done manually, but it's more fun to let your IDE do that job. Move your cursor over the word StatelessWidget.
-
In VS Code, press Ctrl + ., or Command + . on a Mac. In Android Studio/Intellij, press Alt + Enter, or Option + Enter on a Mac. This will bring up a dialog where you can choose which file to import...