Flutter Basic
νλ¬ν°κ° Dart λ₯Ό μ¬μ©νλ μ΄μ
νλ¬ν°κ° Dart λ₯Ό μ¬μ©νλ μ΄μ μ λν΄μ μ μ 리λ κΈμλ λμμκ³ μ± μλ λμμλ―μ΄ λ€νΈκ° JIT μ»΄νμΌ, AOT μ»΄νμΌ λͺ¨λλ₯Ό μ§μνκΈ° λλ¬Έμ΄λ€.
νλ¬ν°μ μ₯μ (= 리μ‘νΈ λ€μ΄ν°λΈμ λΉκ΅νμ¬)
μ± μμλ βμ체 λ λλ§ μμ§μ νμ¬νκ³ μκ³ , λ°λ‘ ARM μ½λλ‘ μ»΄νμΌ νλ€.βλ μ₯μ λλΆμ βμ±μ΄ λ€μ΄ν°λΈλ‘ ꡬλβλλ©° 리μ‘νΈ λ€μ΄ν°λΈμ²λΌ μλ° μ€ν¬λ¦½νΈ λΈλ¦Ώμ§μ κ°μ μ€κ° κ³μΈ΅μ΄ νμκ° μλ€κ³ νκ³ μλ€.
곡μλ¬Έμμμ μ€λͺ νκ³ μλ μν€ν μ²μμ μ΄μ κ΄λ ¨λ μ¬λ¬ λ΄μ©λ€μ νμΈν μ μλλ° λͺλͺ ννλ§ λ΄λ κ°μ λ§₯λ½μμ μ€λͺ νκ³ μλ€.
Flutter is a cross-platform UI toolkit that is designed to allow code reuse across operating systems such as iOS and Android, while also allowing applications to interface directly with underlying platform services.
During development, Flutter apps run in a VM that offers stateful hot reload of changes without needing a full recompile. For release, Flutter apps are compiled directly to machine code, whether Intel x64 or ARM instructions, or to JavaScript if targeting the web.
To the underlying operating system, Flutter applications are packaged in the same way as any other native application. A platform-specific embedder provides an entrypoint; coordinates with the underlying operating system for access to services like rendering surfaces, accessibility, and input; and manages the message event loop.
μ 체μ μΌλ‘ ν λ§λλ‘ μμ½νμλ©΄ νλ¬ν°λ μ΄λ νλ«νΌμ΄λ ν΄λΉ νλ«νΌμμ λμνλ native application μ²λΌ ν¨ν€μ§λκ³ ν΄λΉ νλ«νΌμ μλΉμ€λ€κ³Ό μ§μ μ μΌλ‘ λ§λΏμ λμνλλ‘ μ€κ³λμλ€λ κ²μ΄λ€.
λ°λλ‘ λ¦¬μ‘νΈ λ€μ΄ν°λΈμ κ²½μ° Javascript bridge λ₯Ό κ°μ΄λ°μ λκ³ νλ«νΌ μλΉμ€λ€κ³Ό νλ ₯ν΄μΌν΄μ κ³μλλ μ΄λ²€νΈ λ±μμ λΉμ©μ΄ ν¬λ€. μ΄λ¬ν 리μ‘νΈ λ€μ΄ν°λΈ ꡬλλ°©μ λ° λ¨μ λ€μ μ 리λ λΈλ‘κ·Έκ° λ§μμ λ§ν¬λ§ λ¨κΈ΄λ€.
λͺ¨λ κ²μ΄ μμ ―
νλ¬ν°λ λͺ¨λ κ²μ΄ μμ ―μ΄λ©° μμ ―μ μ‘°ν©μΌλ‘ UIλ₯Ό ꡬμ±νλ€. νλ¬ν°μ λ€λ₯Έ κ°μ²΄κ° μλ€λ λ»μ΄ μλκ³ , μ±μ ꡬμ±νλ λͺ¨λ ꡬμ±λ€μ΄ μμ ― νΉμ μμ ―μΌλ‘ μ‘°ν©λ μμ ―μ΄λΌλ λ»μμ βλͺ¨λ κ²μ΄ μμ ―βμ΄λΌλ λ»μ΄λ€.
μ¬κΈ°μ βμ‘°ν©βμ μ κΈ°μ΅ν΄μΌνλ κ²μ΄, νλ¬ν°μμλ κΈ°λ³Έμ μΌλ‘ βμμβμ΄ μλ βμ‘°ν©βμ ν΅ν΄μ μμ ―μ ꡬμ±νλ€. μλ₯Ό λ€μ΄ Button μΌλ‘μ κ³΅ν΅ κΈ°λ₯, 컀μ€ν κΈ°λ₯μ΄ λ λ€ νμν κ²½μ°μ μΌλ°μ μΌλ‘ κ°μ²΄ μ§ν₯ λ°©μμΌλ‘ 곡ν΅λλ λΆλͺ¨ Button μ λ§λ€κ³ μ΄λ₯Ό μμλ°μμ 컀μ€ν Button μ λ§λλκ² μλλΌ μ»€μ€ν Button μ κ³΅ν΅ Button μ βμ‘°ν©βν΄μ ꡬνν΄μΌ νλ€.
StatelessWidget vs StatefulWidget
StatelessWidget
StatelessWidget μ νλ μμν¬μ κ·Έ μ΄λ€ κ²λ μλ¦¬μ§ μλλ€. νλ μμν¬μμ μμ ―μ μΈμ 리λΉλ ν΄μΌνλμ§ μλ €μ€λ€. μ² μ νκ² μΈλΆ(=νλ μμν¬)μ μν΄μ μλͺ μ΄ κ²°μ (βμλͺ μ΄ κ²°μ β λλ€λ λ§μ μμ ―μ μλͺ μ£ΌκΈ°κ° μλμ μΌλ‘ λ°μνλ€λ μλ―Έμ΄λ€.)λλ€.
μλμ μΌλ‘ μ² μ ν μ μλ κΈ°λ₯μ μννλ€. μ¦, μνκ° μλ μμ ―μΌλ‘μ μλ‘μ΄ μ 보μ λ°μ(react)νλ€.
StatefulWidget
StatefulWidget μ νμ State κ°μ²΄λ₯Ό κ°λλ€. State κ°μ²΄λ setState()λλ λ©μλλ₯Ό κ°κ³ μλλ°, μμ ―μ λ€μ κ·Έλ €μΌν¨μ νλ¬ν°μ μ리λ κΈ°λ₯μ μννλ€. μ΄ ν¬μΈνΈμμ StatelessWidget μ ν¬κ² ꡬλ³λλ€. StatelessWidget λ νλ μμν¬μ μμ¬ννμ ν μ μλλ° λ°ν΄, StatefulWidget λ μΈμ μμ ―μ λ€μ κ·Έλ €μΌνλμ§μ λν΄μ νλ μμν¬μ μμ ―μ΄ λ°μΈκΆμ κ°μ§κ³ μλ κ²μ΄λ€.
setState() μ΄ λ°μν κ²½μ° ν΄λΉ μμ ― λΏλ§ μλλΌ ν΄λΉ μμ ―μ μμ‘΄νλ λͺ¨λ μμ ―μ λ€μ κ·Έλ €μΌνλ€κ³ νλ μμν¬μ μ§μνλ€.
StatefulWidget μμ ― μλͺ
μ£ΌκΈ°

μΆμ²: https://betterprogramming.pub/stateful-widget-lifecycle-a01c44dc89b0
StatefulWidget μμ ― μλͺ μ£ΌκΈ° μ΄λ―Έμ§ μΆμ²μ΄κΈ°λ ν ν¬μ€ν μ μμ£Ό μμΈν κ° μλͺ μ£ΌκΈ° λ©μλμ λν΄ μ λ¦¬κ° λμ΄ μλ€. μ΄ μ€ didUpdateWidget(), setState() μ΄ κ°μ κ³μΈ΅μ μμ΄ μ‘°κΈ λ νμ€νκ² κ΅¬λΆ ν΄λλ©΄ μ’μ κ² κ°μμ λ°λ‘ μλμ μ μ΄λλ€.
didUpdateWidget() Gets called if the parent widget changes its configuration and has to rebuild the widget. The framework gives you the old widget as an argument that you can use to compare it with the new widget. Flutter will call the build() method after it. Tip: Use this method if you need to compare the new widget to the old one.
@override
void didUpdateWidget(covariant MyHomePage oldWidget) {
super.didUpdateWidget(oldWidget);
// TODO: implement didUpdateWidget
}
setState() This method is often called from the Flutter framework itself and from the developer. The setState() method notifies the framework that the internal state of the current object is βdirtyβ, which means that it has been changed in a way that might impact the UI. After this notification, the framework will call the build() method to update and rebuild a widget. Tip: Whenever you change the internal state of a State object, make that change in the setState() method.
setState(() {
// implement setState
});
νλ¬ν° λ λλ§ λμ μ리
νλ¬ν°κ° μμ ―μ νλ©΄μ λ λλ§ νκΈ°κΉμ§ λ§μ κ³Όμ μ κ±°μΉλ€. μ΄λ₯Ό μμΈν μμ보λ μ±ν°μλ€. λ λλ§ νκΈ°κΉμ§μ κ³Όμ μ μλμ κ°λ€.
μμ ― νΈλ¦¬ μμ± -> λ μ΄μμ μ²λ¦¬(μμμ μλλ‘ βμ μ½β μ ν -> μλμμ μλ‘ βν¬κΈ°β μ€μ ) -> 쑰립 -> Rasterization

μΆμ² : Flutter In Action
μ μ½ : μμ λ ΈλμΌ. λλ μ΅λ 50px λλΉλ₯Ό κ°μ§ μ μκ³ νλ©΄ νλ¨μ μ λ°μ μ°¨μ§ν μ μμ΄.
ν¬κΈ° : λΆλͺ¨ λ Έλλ. μ λ 25 x 25 px μ μ°¨μ§νκΈ°λ‘ κ²°μ νκ³ , μΌμͺ½ μ μμ μ μ (200, 30) μ΄μμ.
μμ ― νΈλ¦¬ μμ±
νλ©΄μ ꡬμ±νλ μμ ―λ€ μ체μ μ 보μ μμ ―κ°μ μ λ³΄κ° λ΄κΈ΄ μμ ― νΈλ¦¬λ₯Ό λ§λ λ€.
λ μ΄μμ μ²λ¦¬(μμμ μλλ‘ βμ μ½β μ ν -> μλμμ μλ‘ βν¬κΈ°β μ€μ )
μμ ― νΈλ¦¬κ° μμ±λλ©΄ μμμ μλλ‘(λΆλͺ¨μμ μμ λ°©ν₯μΌλ‘) βμ μ½βμ΄ μ νλλ€. βμ μ½βμ΄ λͺ¨λ μ νλκ³ μλμμ μλ‘(μμμμ λΆλͺ¨ λ°©ν₯μΌλ‘) βν¬κΈ°βκ° μ νλλ€.
쑰립
μμ ― νΈλ¦¬ μμ± λ° λ μ΄μμ μ²λ¦¬κ° λͺ¨λ λλκ³ λ°λ‘ λμ€ν°λΌμ΄μ§νμ§ μκ³ , β쑰립βμ κ³Όμ μ κ±°μΉλ€. μ΄ κ³Όμ μμ μμ ―μ μ€μ μμ μ΄ μ²λ¦¬ν ν½μ μ μλ₯Ό μκ² λλ€. κ·Έλ¦¬κ³ μ΄ κ³Όμ μμ κΈ°μ‘΄μ μ»΄ν¬λνΈλ₯Ό μ¬μ¬μ©μ²λ¦¬ νκ² λλ€.
Rasterization
Rasterization λ¨μ΄ μμ²΄κ° μλ―Ένλ κ·Έλλ‘μ νμμ΄λ€. νλ¬ν° μ체 λ λλ§ μμ§μ ν΅ν΄μ ν½μ μ μ±μ°λ κ³Όμ μ΄λ€.
Last updated