Dart

이은서·2024년 9월 2일

Flutter

목록 보기
3/3

0.1~0.2. Why Dart

· Compiler {type}

Dart WebDart Native
translates Dart code into jstranslates Dart code to various architectures of CPU.

· {How} Dart gets compiled(remarkable feature compared to other languages)

Compiling for an Architecture(MacOS, Windows, etc) takes a lot of time.
The most well-known compiler type is AOT.

AOT(Ahead of Time): You compile first, then distribute the resulting binary(CPU understandable). This means that you have to compile the whole project to see the result every time you make a change.
JIT(Just in Time): Will show you the results of your code right away, using the dart VM. Because this means that code is running on vm, it means that it will take more time running your code, only during development.

Under developmentAfter developing
JIT(Dart VM)AOT

Another feature: null safety

Referencing a null value invokes serious crash issues, and so Dart chose to apply this feature.

Flutter chose Dart because 1. Dart has both AOT and JIT, which makes it so much easier to build a mobile app. 2. Also, Dart and Flutter are both powered by Google, so Google is able to optimized Dart for Flutter.

※ Dart 문법에서는 세미콜론(;)이 사용되기도 하고 사용되지 않기도 하기 때문에 유의해서 코딩해야 한다.




1.1~1.6 Variables

· 2 ways of creating variables

⌗1 : var (변수 이름) = (데이터);

  • No need to specify data type (dart compiler automatically detects it)
  • When to use: Inside of functions, methods(local variables)

⌗2: String (변수 이름) = (데이터);

  • This time, you can specify the data type.
  • When to use: when working with classes

· dynamic type

var (변수 이름);  // dynamic (변수 이름); 과 같다.
(변수 이름) = moni;
(변수 이름) = 12;
(변수 이름) = true;
  • Dart is in some means user-friendly; if you declare a variable without adding any data to it, the variable becomes a dynamic type, which means you can assign any value afterwards.
  • When to use: when it is hard to actually know the type of the variable, especially when working with flutter or json
  • Use it only when you need to

Example:

void main() {
    dynamic name;
    if(name is String) {
        name.length… ;
    }
    if(name is int) {
        name.isFinite… ;
    }
// 인터넷에서 데이터를 가져왔는데 타입을 모를 경우, dart가 데이터 타입을 확인할 수 있도록 도와줄 수 있다. 

0개의 댓글