【发布时间】:2020-07-24 09:59:18
【问题描述】:
我有一个仪表板小部件,其主体如下:
我想将数据从子小部件 DashboardGrid(在代码块末尾检查)传递到此父小部件。我该怎么做?
body: Column(
children: <Widget>[
SizedBox(
height: 20,
),
Padding(
padding: EdgeInsets.only(left: 16, right: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Categories",
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold)),
],
),
IconButton(
alignment: Alignment.topCenter,
icon: new Icon(Icons.search, color: Theme.of(context).hintColor,),
onPressed: () {},
)
],
),
),
SizedBox(
height: 40,
),
DashboardGrid(),
])
【问题讨论】:
-
只需将一个函数作为参数从 parent 传递给 DashboardGrid() ,然后通过传递您要传递的所需数据来调用该函数。由于该函数是在 Parent 小部件类中定义的,因此您可以在该函数中评估数据