我想將資料從子小部件傳遞到父小部件,但我不能使用提供程式,所以我嘗試將值傳遞給新的類建構式,然后在我想要的任何地方使用它,但這對我來說并不順利
// this is the code that run when pressing the button
updatefn: (){
Data(
textFieldName: controllerName,
textFieldImage: controllerImage,
textFieldDetails: controllerDetails,
textFieldLongitude: controllerLon,
textFieldLatitude: controllerLat
);
Data().printText();
collect.reference.update({
'Name': Data().textFieldName.toString(),
'Image': Data().textFieldImage.toString(),
'details':Data().textFieldDetails.toString(),
}).whenComplete(() => Navigator.pop(context));
print("updated");
},
//and this is the class
class Data{
Data({this.textFieldDetails,this.textFieldImage,
this.textFieldLatitude,this.textFieldLongitude,this.textFieldName,
this.currentLat,this.currentLon});
final textFieldLatitude;
final textFieldLongitude;
final textFieldName;
final textFieldImage;
final textFieldDetails;
}
uj5u.com熱心網友回復:
你沒有將Data你構造的東西分配給任何東西,你每次呼叫時都會創建一個新變數Data(),所以所有值都是空的。它應該是這樣的:
var data = Data(
textFieldName: controllerName,
textFieldImage: controllerImage,
textFieldDetails: controllerDetails,
textFieldLongitude: controllerLon,
textFieldLatitude: controllerLat
);
data.printText();
collect.reference.update({
'Name': data.textFieldName.toString(),
'Image': data.textFieldImage.toString(),
'details':data.textFieldDetails.toString(),
}).whenComplete(() => Navigator.pop(context));
print("updated");
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/441452.html
