Jul 9, 2024
Run
to execute codeprint('Hello')
must be terminated with a semicolon ;
String text = 'Hello';
double decimal = 5.5;
int number = 5;
.toString()
to convert numbers to strings for printingconst
values known at compile timefinal
values initialized at runtimeconst String food = 'Pizza';
final String topping = 'Bacon';
switch(variable) {
case 'value1':
// code
break;
case 'value2':
// code
break;
default:
// code
}
if (condition) {
// code if true
} else {
// code if false
}
for (int i = 0; i < 5; i++) {
print(i.toString());
}
?
makes a variable nullable (can be null)!
asserts that a value is non-nullbool? isAdmin = null; // Nullable boolean
if (text == 'Pizza') {
isAdmin = true;
}
print(isAdmin!); // Asserts isAdmin is non-null
cd
(change directory)flutter create project_name
Ctrl + J
: Show/Hide terminalCtrl + B
: Show/Hide explorerScaffold
: Basic structure of the appAppBar
: Top bar of the app
AppBar(
title: Text('Title'),
centerTitle: true,
backgroundColor: Colors.red,
)
body
: Central area of the appimages
folderpubspec.yaml
Image.asset('images/your_image.png')
Image.network
to display images from a URL
Image.network('image_url')
Center(
child: Image.asset('images/your_image.png'),
)
Format Document
ElevatedButton
: Simple button with customizable style
ElevatedButton(
onPressed: () {
// action
},
child: Text('Click Me'),
)
styleFrom
:
ElevatedButton.styleFrom(
primary: Colors.green,
)
setState
setState(() {
variable = newValue;
});
SizedBox(height: 50.0)
SingleChildScrollView(
child: Column(
children: [
// widgets
]
),
)
List.generate(3, (index) => Image.asset('images/image.png'))
(context) => Image.asset('images/image.png')
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {},
child: Text('Button 1'),
),
SizedBox(width: 20),
ElevatedButton(
onPressed: () {},
child: Text('Button 2'),
),
],
)
Navigator.push
to navigate
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NewPage(),
),
);
Scaffold
in new pages for structureNavigator.of(context).pop()
to return to the previous page