Skip to content

Instantly share code, notes, and snippets.

@doyle-flutter
Last active January 29, 2024 05:15
Show Gist options
  • Save doyle-flutter/0565530177cd924b64c726744d0095c1 to your computer and use it in GitHub Desktop.
Save doyle-flutter/0565530177cd924b64c726744d0095c1 to your computer and use it in GitHub Desktop.
class01 type Operator
void main() {
/// type
int a = 0;
double a2 = 0.2;
String b = "b";
String b2 = "bOb";
bool c = true;
bool c2 = false;
List d = [];
List d2 = [1,"2",false];
List<int> d3 = [1,2,3];
List<String> d4 = ["4","5","6"];
print("List index 0 = ${d4[0]}");
Set e = {};
Set<dynamic> e2 = {1,2,"3"};
Set<int> e3 = {4,5,6};
print("Set first = ${e3.first}");
print("Set -> List index 1 = ${e3.toList()[1]}");
Map f = {};
Map<String, dynamic> f2 = {"k":1, "k2": "v2"};
Map<String, int> f3 = {"k":1, "k2":2};
Map<int, int> f4 = {0:1, 1:2};
print("Map Key 'k' = ${f3["k"]}");
print("Map Key 0 = ${f4[0]}");
/// operator
print( 1 + 1 );
print( 2 - 2 );
print( 3 * 3 );
print( 4 / 2 );
print( 4 % 3 ); // 나머지
print( 4 ~/ 3 ); // 몫
print( null ?? 55 );
print( true ? 66 : 777 );
print( 0 > 10 );
print( 0 < 10 );
print( 2 >= 2 );
print( 2 <= 3 );
print( 3 == 3 );
// - spread
final li = [1,2,3];
final li2 = [...li, 4,5,6];
print(li2);
final mapSpread = {"k":1};
final mapSpreadSum = {...mapSpread, "k2": 2};
print(mapSpreadSum);
// - addition assignment 더하기 할당
int value = 1;
value += 2; // value = value + 2;
print(value);
value -= 1; // value = value - 1;
print(value);
value *= 1; // value = value * 1;
print(value);
// - in(de)crement
value++;
print(value);
value--;
print(value);
// or / and
print( value > 0 || value < 100);
print( value > 0 && value < 2);
//Optional chaining
Model? model;
model?.a;
model?.func();
}
class Model{
int a = 0;
void func() => 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment