[英]How call setState from child widget*
我有 3 个选项卡的 DefaultTabController。 其中一个选项卡是一个列表。 我需要在单击列表项时,其他小部件上的当前列表更改。 我该怎么做呢? 谢谢你。 选项卡状态类
class StationState extends State<Stations> {
Widget secondWidget;
@override
Widget build(BuildContext context) {
secondWidget = Styles(this);
return DefaultTabController(
length: 3,
child: Scaffold(
backgroundColor: Color(0xFF000000),
appBar: AppBar(
title: HeaderLogo(),
backgroundColor: Color(0xFF000000),
bottom: TabBar(
indicatorColor: Colors.white,
tabs: [
Tab(
text: 'Favorites',
),
Tab(
text: 'Genres',
),
Tab(
text: 'Networks',
),
],
),
),
body: TabBarView(children: [
Favorites(),
secondWidget,
Networks(),
]),
),
);
;
}
}
请添加您的代码以更好地帮助您。
但是你可以向列表项传递一个回调,当列表项被点击时,回调被触发。
像这样的东西
return ListItem(
onPressed: () {
setState((){
//Do what you need on the parent
});
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.