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



}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM