網路上抓的 life cycle 目前先專注在 createState / initState / build / setState 上即可
// 條件判斷:必須放 boolean
print(1 == 1); // true
print(1 != 1); // false
print(2 > 2); // false
print(2 >= 2); // true
print(4 < 3); // false
print(4 <= 3); // false
// "=" 賦值用
x = x + 1;
// "==" 條件判斷用
if (x == y) {
print('EQUAL!');
} else {
print('x = $x');
print('y = $y');
print('NOT EQUAL!');
}
// 前一小節使用 ternary-operator
Widget activeScreen = screen == 'start' ? Start(switchScreen) : const Quiz();
// ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
// 條件判斷 true 的狀況 false 的狀況
// 作用 *幾乎* 相同
Widget? screen;
if (screen == 'start') {
screen = Start(switchScreen);
} else {
screen = const Quiz();
}
// 單行可以省略 {}
Widget? screen;
if (screen == 'start')
screen = Start(switchScreen);
else
screen = const Quiz();
// 可以簡化
Widget screen = Start(switchScreen);
if (screen != 'start')
screen = const Quiz();
// 單行可以縮成一排
Widget screen = Start(switchScreen);
if (screen != 'start') screen = const Quiz();
final myList = [
1,
2,
if (condition)
3
];
// [1, 2, 3] if condition true
// [1, 2] if condition false
final myList = [
1,
2,
if (condition)
3
else
4
];
final myList = [
1,
2,
condition ? 3 : 4
];
← 如果不是最後一項的話,記得要加 ,
逗號