扑面而来
我试图将选定项目的列表屏幕返回到先前的屏幕。 Android没问题,但iOS没有运气。正确的滑动未调用从列表中返回选定项目数组的OnWillPop函数。
我创建了一个CustommaterialPageroute:
类CustommaterialPageroute扩展了材料pageroute { @protected bool获得hasscopedwillpopcallback { 返回false; } CustommaterialPageroute({ 必需的widgetbuilder构建器, 所需的路由设置, bool navialstate = true, bool fullscreendialog = false, }) : 极好的( 建筑商:建筑商, 设置:设置, 维护省:维护状态, FullScReendialog:FullScreendialog, ); }
我通过以下方式拨打列表屏幕:
void _getTurnpointsfortask()async { 最终结果=等待Navigator.pushnamed(上下文,Thrpointsfortask.Routename, 参数:Thrpointssearchinappbarscreen.task_turnpoint_option,); 如果(结果为列表< Thrpoint>){//结果恢复为null。 blocProvider.of< taskbloc>(上下文).add(TurnpointSaddedTotAsKevent(result)); } }
路由代码是:
if(settings.name == thrpointsfortask.routename){ 最终ViewOption = settings.arguments as String; 返回CustommaterialPageroute( 建筑商:(上下文){ 返回Turnpointsfortask(ViewOption:ViewOption); },, 设置:设置, );
}
列表屏幕构建以:
开头@Override 小部件构建(buildContext上下文){ 返回条件意外popscope( OnWillPop:_ONWILLPOP, syseaddcallback:widget._haschanges,//< _haschanges是正确的 孩子:脚手架( 钥匙:_scaffoldkey, ...
使用Android Back按钮调用的_ONWILLPOP代码,但不用iOS正确滑动:
Future< bool> _ONWILLPOP()ASYNC { if(widget.viewoption == turnpointssearchinappbarscreen.task_turnpoint_option){ aCkaffoldMessenger.of(context).removecurrentsnackbar(); navigator.of(context).pop(widget.turnpointsfortask); <<<返回物品阵列 } 别的 { navigator.of(context).pop(); } 返回true; }
我缺少什么?
I am attempting to have a list screen return am array of selected items to a prior screen. No problem in Android, but no luck in iOS. The right swipe does not call the onWillPop function that returns an array of selected items from the list.
I have created a CustomMaterialPageRoute:
class CustomMaterialPageRoute extends MaterialPageRoute { @protected bool get hasScopedWillPopCallback { return false; } CustomMaterialPageRoute({ required WidgetBuilder builder, required RouteSettings settings, bool maintainState = true, bool fullscreenDialog = false, }) : super( builder: builder, settings: settings, maintainState: maintainState, fullscreenDialog: fullscreenDialog, ); }
I call the list screen via:
void _getTurnpointsForTask() async { final result = await Navigator.pushNamed(context,TurnpointsForTask.routeName, arguments: TurnpointsSearchInAppBarScreen.TASK_TURNPOINT_OPTION,); if (result is List<Turnpoint>) { // result comes back null. BlocProvider.of<TaskBloc>(context).add(TurnpointsAddedToTaskEvent(result)); } }
The route code is:
if (settings.name == TurnpointsForTask.routeName) { final viewOption = settings.arguments as String; return CustomMaterialPageRoute( builder: (context) { return TurnpointsForTask(viewOption: viewOption); }, settings: settings, );
}
The list screen build starts with:
@override Widget build(BuildContext context) { return ConditionalWillPopScope( onWillPop: _onWillPop, shouldAddCallback: widget._hasChanges, //<_hasChanges is true child: Scaffold( key: _scaffoldKey, ...
The _onWillPop code which is called with Android back button, but not with iOS right swipe:
Future<bool> _onWillPop() async { if (widget.viewOption == TurnpointsSearchInAppBarScreen.TASK_TURNPOINT_OPTION) { ScaffoldMessenger.of(context).removeCurrentSnackBar(); Navigator.of(context).pop(widget.turnpointsForTask); <<< return array of items } else { Navigator.of(context).pop(); } return true; }
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是最好的解决方案,但可以正常工作。
}
Not sure this is the best solution, but it works.
}