Loading the lesson...
In the print dialog, choose "Save as PDF" as the destination.
Operating Systems 2 - Lab 3
Debugging habits, images, StatelessWidget structure, and core layout widgets
// ERROR: Missing comma between properties
Container(
color: Colors.blue
width: 100, // IDE highlights this line
)// FIXED: Added the missing comma
Container(
color: Colors.blue,
width: 100,
)Expected to find ','. Add the missing comma.MaterialAppScaffoldMaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('My First App')),
body: Center(child: Text('Hello, Flutter!')),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Icon(Icons.add),
),
),
)Image.network loads an image from a URL, with optional width/heightImage.asset loads a local image bundled with the projectpubspec.yaml under the assets section before they'll loadflutter:
assets:
- images/logo.pngStatelessWidgetStatelessWidget implements a build method that returns its widget treemain.dartmain.dart
MaterialApp
home: HomeScreen
home_screen.dart
StatelessWidget
Scaffold
Body widgets
Margin
space outside the border
Padding
space inside the border
Child widget
Padding widget when you need spacing without color or bordersCenter explicitly centers a child inside its parentContainer(
margin: EdgeInsets.all(20),
padding: EdgeInsets.all(16),
child: Text('I have margin and padding!'),
)RowRow(
children: [
Icon(Icons.star, color: Colors.amber),
Icon(Icons.star, color: Colors.amber),
Icon(Icons.star_border, color: Colors.amber),
],
)Columnchildren list, unlike Container which takes only one childmainAxisAlignment controls spacing along the primary axiscrossAxisAlignment controls alignment along the secondary axis| Value | Effect |
|---|---|
MainAxisAlignment.start | Pack children at the start (default) |
MainAxisAlignment.center | Center children along the axis |
MainAxisAlignment.end | Pack children at the end |
MainAxisAlignment.spaceBetween | Equal space between children, no space at edges |
MainAxisAlignment.spaceEvenly | Equal space between and around children |
MainAxisAlignment.spaceAround | Half space at edges, full space between |
SafeArea to automatically add the padding needed to avoid themMaterialApp + Scaffold form the standard screen skeleton; images load via Image.network or Image.assetStatelessWidget classes, one per file, to keep code maintainableRow and Column arrange multiple children; mainAxisAlignment/crossAxisAlignment control their spacingSafeArea keeps content clear of notches and system UIMahmoud Abas|Lab: Flutter UI Basics, Layouts, and Code Organization