main(List args) {
    String name = “why”;

    var age = 20;

    age = 30;

    final height = 1.88;

    const address = “广州市”;

    // const 必须赋值(编译期间确定一个值),final可以通过(运行期间确定一个值)

    const p1 = Person(“why”);

    const p2 = Person(“why”);

    print(identical(p1, p2));
    }

    class Person {
    final String name = “”;
    const Person(String name);
    }

    字符串

    var name = “why”;
    var age = 19;
    var height = 1.88;

    var message = “my name is ${height}”;

    集合
    main(List args) {
    // List
    var names = [“abc”, “cba”, “nba”];
    // Set
    var movies = {“流浪地球”, “大话西游”};
    // Map
    var info = {“name”: “why”, “age”: 18};
    }

    函数

    main(List args) {
    print(sun(2, 4));
    }

    int sun(int num1, int num2) {
    return num1 + num2;
    }

    函数可选参数

    main(List args) {}

    //位置可选参数
    void sayHello(String name, [int age, double height]) {}

    void sayHello2(String name, {int age = 2, double height}) {}

    函数

    main(List args) {
    test(bar);

    test(() {
    print(“ssssssssss”);
    return 10;
    });
    // 箭头函数
    test(() => print(“ssssssssssssssssssss”));
    }

    void test(Function foo) {
    var result = foo();
    }

    void bar() {
    print(“ssssssssss”);
    }

    函数类型定义

    main(List args) {
    test((num1, num2) {
    return num1 + num2;
    });

    var d = demo();
    print(d(20, 30));
    }

    typedef Calculate = int Function(int num1, int num2);

    void test(Calculate calc) {
    calc(20, 30);
    }

    Calculate demo() {
    return (int num1, int num2) {
    return num1 * num2;
    };
    }