java init方法_父级重建时调用子init方法 - flutter
据我了解和颤振的工作机制,有状态窗口小部件方法只在每次更改其状态或重建父窗口时调用窗口小部件树和构建方法方法时才调用一次 .bottomNavigationBar: BottomNavigationBar(items: [BottomNavigationBarItem(icon: new Icon(Icons.home,), title: new Text("HOME", style: new T
据我了解和颤振的工作机制,有状态窗口小部件方法只在每次更改其状态或重建父窗口时调用窗口小部件树和构建方法方法时才调用一次 .
bottomNavigationBar: BottomNavigationBar(items: [
BottomNavigationBarItem(icon: new Icon(Icons.home,), title: new Text("HOME", style: new TextStyle(fontSize: 11.0),),),
BottomNavigationBarItem(icon: new Icon(Icons.message,), title: new Text("MESSAGES", style: new TextStyle(fontSize: 11.0),),),
BottomNavigationBarItem(icon: new Icon(Icons.notifications,), title: new Text("NOTIFICATIONS", style: new TextStyle(fontSize: 11.0),),),
BottomNavigationBarItem(icon: new Icon(Icons.assignment,), title: new Text("MENTOR", style: new TextStyle(fontSize: 11.0),),),
BottomNavigationBarItem(icon: new Icon(Icons.account_circle,), title: new Text("PROFILE", style: new TextStyle(fontSize: 11.0),),),
],
onTap: (int index){
setState(() {
_currentActiveIndex = index;
});
},
currentIndex: _currentActiveIndex,
type: BottomNavigationBarType.shifting,
),
body: _getCurrentPage(_currentActiveIndex),
_currentActiveIndex这里是一个类的状态之一,其中基于_currentActiveIndex的值呈现单独的正文窗口小部件 .
body: TabBarView(children: [
new PostLoadWidget.express(),
new PostLoadWidget.confess(),
]),
这是scaffold小部件的主体: - 基于上面的_currentActiveIndex呈现的小部件 .
class PostLoadWidgetState extends State {
@override
void initState(){
print("initState is called here);
super.initState();
}
}
每次更改_curentActiveIndex的父项重建(上图)时,都会调用PostLoadWidgetState initState()方法,这是所需的行为 . 我一直在初始化initState()中的网络调用,我不想在每次重建父节点时调用它 .
更多推荐


所有评论(0)