大佬教程收集整理的这篇文章主要介绍了关闭 ModalBottomSheet 时的 Flutter 返回数据,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当在屏幕上按下 FAB 时,我正在显示一个 ModelBottomSheet。当 ModelBottomSheet 弹出时,我使用从 ModelBottomSheet 返回的数据运行一个方法,该方法更新屏幕。
onpressed: () {
print('FAB pressed');
showModalBottomSheet<SearchData>(
isScrollControlled: true,context: context,builder: (context) => SingleChildScrollVIEw(
child: SearchScreen(
searchData: _searchData,LOCATIOnEnabled: !userposition.error,),).then((value) => _updateList(value));
},
在 ModelBottomSheet 上,我有一个按钮可以弹出 ModelBottomSheet 并返回数据 (_searchData)。
Elevatedbutton(
onpressed: () {
print('search button pressed');
if (_textSearch.text == null || _textSearch.text.isEmpty) {
_searchData.searchTerm = '';
} else {
_searchData.searchTerm = 'value=${_textSearch.text}';
}
if (_IDSearch.text == null || _IDSearch.text.isEmpty) {
_searchData.guIDEID = '';
} else {
_searchData.guIDEID = '&LOCATIOn=${_IDSearch.text}';
_searchData.showOfficial = false;
}
Navigator.pop(context,_searchData);
},
当 ModelBottomSheet 被关闭(即用户点击屏幕的上半部分)时,如何获得与按下 ModelBottomSheet 上的按钮相同的结果?
您可以使用 WillPopScope 包装您的 ModalWidget。你可以看下面的例子
WillPopScope(
onWillPop: () async {
Navigator.pop(context,data);
return true; // return true if needs to be popped
},child: ModelWidget(
…
),);
这将确保在使用后退按钮自动弹出时调用 Navigator.pop。
信用:How can I control what is passed to Navigator.pop() when clicking outside of a showModalBottomSheet?
以上是大佬教程为你收集整理的关闭 ModalBottomSheet 时的 Flutter 返回数据全部内容,希望文章能够帮你解决关闭 ModalBottomSheet 时的 Flutter 返回数据所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。