플러터 글자 넣기, 아이콘 넣기, 하위 위젯 자식요소에 주의하기

2022. 4. 23. 20:13Flutter 플러터/플러터 몰랐던 것

 

1. 글자넣기

Text (" dd " ),

 

2. 아이콘 넣기

Icon(Icons.아이콘명),

 

두 위젯 사용에서 상위위젯이 존재하면 child : Text or child : Icon 등으로 작성해주면 된다.

단, 이때 아래의 경우에는 조금 다른 작성이 필요하다

 

3. 자식요소

materialapp, appbar는 무조건 하위위젯에 child 쓰는게 아니라 각 위젯이 가진 요소를 명확히 불러야한다.

 

MaterialApp은 home, appBar는 title 

NP 1. 앱바에 글자 넣을 땐 title : 로 앱바가 가진 child를 표시.

appBar: AppBar(
          title : const Text('앱임'),
        ),

NP 2. 기본 materialapp 안에서 scaffold 설정할 땐 home : 으로 앱이 가진 child를 표시

 

return MaterialApp(
      home : Scaffold(
        appBar: AppBar(
          title : const Text('앱임'),
        ),

        body: const Center(
          child : Text('안녕'),
        ),

        bottomNavigationBar: BottomAppBar(
        ),
      ),
    );

 

NP 3. 아이콘

아이콘 위젯 사용시 대문자 Icon() 안에서 여러 아이콘중에 하나를 불러오는 것이므로 Icons.특정아이콘명

 

예시

child : Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: const [
              Icon(Icons.call),
              Icon(Icons.home),
              Icon(Icons.favorite),
            ],
          ),

 

아이콘은 Icon (Icons.아이콘명)