변수명 앞에 언더바(_)를 붙이면 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();
}
}
'코딩 > Flutter' 카테고리의 다른 글
Dart 언어 문법 삼항 연산자 및 ?, ?? 사용 (0) | 2023.04.08 |
---|---|
[Flutter] Extends, Override, build, BuildContext에 대해 알아보기 (0) | 2022.04.28 |
[Flutter] final 변수와 const 변수 (0) | 2022.04.27 |
[Flutter] 상태관리란 무엇인가 (0) | 2022.04.27 |
[Flutter] Stateless Widget과 Stateful Widget의 차이 (0) | 2022.04.26 |
댓글