【发布时间】:2020-11-28 20:33:51
【问题描述】:
我有一个主小部件屏幕,其中包含两个主要小部件,一个标题(用红色标记)和一个列表(用紫色标记)
这是我的代码:
class ScreenClient extends StatefulWidget {
_ClientState createState() => _ClientState();
}
class _ClientState extends State<ScreenClient> {
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
ClientHeader(), // this is my header widget red
Expanded(
child: ClientList(), // this is my list widget purple
),
],
);
}
}
标题小部件有三个选项,如您所见 Tous Bloqué 和 ayant Retard ,我想要实现的是将单击选项的值传递给标有紫色的列表小部件(因为这些选项是过滤器,列表元素应根据所选选项显示)
我很难理解状态管理包,据我了解Global Keys 可以做到这一点,但如何? .
这是我的标题小部件代码:
class ClientHeader extends StatefulWidget {
_HeaderClientState createState() => _HeaderClientState();
}
class _HeaderClientState extends State<ClientHeader> {
String nomSituation;
String option = "Tous";
@override
Widget build(BuildContext context) {
return Container(
child: Row(
children: <Widget>[
GestureDetector(
child: Text(
"Tous",
style: TextStyle(
color: option == "Tous" ? Colors.white : Colors.grey[400],
),
),
onTap: () {
setState(() {
option = "Tous";
});
},
),
GestureDetector(
child: Text(
"Bloqué",
style: TextStyle(
color: option == "Bloqué" ? Colors.white : Colors.grey[400],
),
),
onTap: () {
setState(() {
option = "Bloqué";
//add send value to ClientList widet ?
});
},
),
GestureDetector(
child: Text(
"Ayant Retard",
style: TextStyle(
color:
option == "Ayant Retard" ? Colors.white : Colors.grey[400],
),
),
onTap: () {
setState(() {
option = "Ayant Retard";
});
},
),
],
),
);
}
}
【问题讨论】:
-
你也可以为你的clientList添加代码吗?
标签: flutter dart flutter-layout