我在 showModalBottomSheet 中找到了 Navigator.pop(context, data) 的解決方案
這是解決方案
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Padding(
padding: EdgeInsets.fromLTRB(0, AppBar().preferredSize.height, 0, 0),
child: CountryPicker(
countryCodes: countryCodes,
),
);
},
).then((value) {
setState(() {
countryCodeIndex = value;
});
});
但我不能在 showBottomSheet 中使用方法
這是我得到的錯誤
The method 'then' isn't defined for the type 'PersistentBottomSheetController'.
Try correcting the name to the name of an existing method, or defining a method named 'then
我如何從 showBottomSheet 接收資料
uj5u.com熱心網友回復:
使用showModalBottomSheet你可以使用then()或await
當您必須使用showBottomSheet()它時,它會回傳一個PersistentBottomSheetController具有closedFuture<T> 型別的屬性,該屬性也可以與then()or一起使用await。檢查 API 檔案:https ://api.flutter.dev/flutter/material/PersistentBottomSheetController-class.html
編輯:我做了一些進一步的研究:似乎 showBottomSheet 沒有按預期作業。有一個問題(https://github.com/flutter/flutter/issues/66837),其中指出Navigator.pop(context)資料不起作用......所以如果可能的話,我建議使用``
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/491022.html
標籤:扑
上一篇:滑塊不移動但值發生變化
下一篇:顫振設定行的寬度
