Flutter 父子组件传值

一父传子:

父中:

void onButtonChange(val1,val2,val3){
print('============================子向父传值OK了===============');
print(val1);
print(val2);
print(val3);
print('============================子向父传值OK了===============');
}

List list=[["A","A"],["X","S","W"],["H","I","O"]];
new ButtonsWidget(data3Two:list, callback: (val1,val2,val3) => onButtonChange(val1,val2,val3)),

子中:

class ButtonsWidget extends StatefulWidget {
ButtonsWidget({Key key, this.data3Two, this.callback})
:super(key: key);
final callback;
List data3Two;
@override
_ButtonsWidgetState createState() => new _ButtonsWidgetState();
}

class _ButtonsWidgetState extends State<ButtonsWidget> {
  
@override
Widget build(BuildContext context) {
return ViewBuild(
Container(
child: Column(
children: <Widget>[
//省略
        Text(widget.data3Two[0][0]); //拿值得方法
        ],
),
)某工具.onTap((){
    doPostAjax()
}).padding()略
);
}
void doPostAjax(){
widget.callback(_istypesA1,_istypesA2,_istypesA3);
}



}

相关文章:

  • 2022-01-10
  • 2021-04-13
  • 2022-12-23
  • 2021-08-19
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2022-01-15
相关资源
相似解决方案