Flutter 父子组件传值

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);
}



}
posted @ 2019-07-10 17:36  仔行天下  阅读(5860)  评论(0编辑  收藏  举报