Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

coding etude

[Error] No TabController for TabBar 본문

Flutter(Dart)

[Error] No TabController for TabBar

코코리니 2022. 9. 29. 16:20

TabBar 위젯을 사용하면서 controller를 지정해 주지 않으면 발생하는 오류.

 

controller 는 직접 만들어서 적용해도 되지만 DefaultTabController위젯을 사용해도 된다.

 

// DefaultController 사용예시
@override
Widget build(BuildContext context){
	return DefaultTabController(
    	child: Scaffold(
        	// 기존과 동일하게 작성
        )
    );
}

//////////////////////////////////////////////
// StatefulWidget controller 예시

late TabController _tabController;

@override
void initState() {
	super.initState();
	_tabController = TabController(vsync: this, length: myTabs.length);
}

@override
Widget build(BuildContext context){
	return DefaultTabController(
    	child: Scaffold(
        	.
            .
            .
            child: TabBar(
            	controller: _tabController,
                
            )
        )
    );
}

https://api.flutter.dev/flutter/material/TabController-class.html

 

TabController class - material library - Dart API

Coordinates tab selection between a TabBar and a TabBarView. The index property is the index of the selected tab and the animation represents the current scroll positions of the tab bar and the tab bar view. The selected tab's index can be changed with ani

api.flutter.dev

 

'Flutter(Dart)' 카테고리의 다른 글

[plugin] DotsIndicator(슬라이더 표시)  (0) 2022.10.05
[plugin] GetX (flutter 상태관리)  (0) 2022.09.29
[flutter] elevation  (0) 2022.09.29
[widget] IndexedStack  (0) 2022.09.29
[flutter]flutter란?  (0) 2021.03.23