본문 바로가기
개발/flutter 무작정 따라하기

스테이트풀 위젯의 생명주기

by 잡다백과사전 2021. 3. 1.
반응형
순서 생명주기 내용
1 createState() 처음 스테이트풀을 시작할 때 호출
2 mounted == true createState() 가 호출되면 mounted 는 true
3 initState() State 에서 제일 먼저 실행되는 함수. 한번만 호출
4 didChangeDependencies() initState() 호출 후에 호출되는 함수
5 build() 위젯을 렌더링하는 함수. 위젯을 반환
6 didUpdateWidget() 위젯을 변경해야 할 때 호출하는 함수
7 setState() 데이터를 UI에 적용하기 위해 사용되는 함수
8 deactivate() State가 제거될 때 호출
9 dispose() State가 완전히 제거되었을 때 호출
10 mounted == false 모든 프로세서가 종류된 후 mounted가  false로 됨
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  // This widget is the root of your application.
  @override
  State<StatefulWidget> createState() {
    print('createSate');
    return _MyApp();
  }
}

class _MyApp extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    print('build');
    return MaterialApp(
        home: Scaffold(
      appBar: AppBar(
        title: Text('Fluter Deoo'),
      ),
    ));
  }

  @override
  void initState() {
    super.initState();
    print('initState');
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    print('didChangeDependincies');
  }
}

 

 

반응형