본문 바로가기
코딩/Flutter

[Flutter] 변수명 앞에 붙은 underbar(언더스코어, 밑줄)의 의미

by Say_Young 2022. 4. 26.

변수명 앞에 언더바(_)를 붙이면 private 변수다(11행). 

public 변수는 class 외부에서 접근할 수 있지만

private 변수는 class 외부에서 접근할 수 없다. 

 

그리고 8번째 줄 보면 클래스도 언더바가 붙은 것을 볼 수 있는데, 이는 Stateful Widget 생성시 자동으로 만들어지는 클래스다. 만약 외부에서 접근이 가능하게 만들려면 언더바를 지워야 한다

 

class SearchScreen extends StatefulWidget {
  const SearchScreen({Key? key}) : super(key: key);

  @override
  State<SearchScreen> createState() => _SearchScreenState();
}

class _SearchScreenState extends State<SearchScreen> {
  final TextEditingController _filter = TextEditingController();
  FocusNode focusNode = FocusNode();
  String _searchText = "";
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

댓글