扑面而来

发布于 2025-01-23 21:17:39 字数 1903 浏览 0 评论 0原文

我试图将选定项目的列表屏幕返回到先前的屏幕。 Android没问题,但iOS没有运气。正确的滑动未调用从列表中返回选定项目数组的OnWillPop函数。

  1. 我创建了一个CustommaterialPageroute:

     类CustommaterialPageroute扩展了材料pageroute {
       @protected
       bool获得hasscopedwillpopcallback {
      返回false;
    }
    
     CustommaterialPageroute({
       必需的widgetbuilder构建器,
       所需的路由设置,
       bool navialstate = true,
       bool fullscreendialog = false,
     }) : 极好的(
           建筑商:建筑商,
           设置:设置,
           维护省:维护状态,
           FullScReendialog:FullScreendialog,
         );
    }
     
  2. 我通过以下方式拨打列表屏幕:

      void _getTurnpointsfortask()async {
       最终结果=等待Navigator.pushnamed(上下文,Thrpointsfortask.Routename,
       参数:Thrpointssearchinappbarscreen.task_turnpoint_option,);
       如果(结果为列表< Thrpoint>){//结果恢复为null。
          blocProvider.of< taskbloc>(上下文).add(TurnpointSaddedTotAsKevent(result));
       }
    }
     
  3. 路由代码是:

      if(settings.name == thrpointsfortask.routename){
             最终ViewOption = settings.arguments as String;
             返回CustommaterialPageroute(
               建筑商:(上下文){
                 返回Turnpointsfortask(ViewOption:ViewOption);
               },,
               设置:设置,
             );
     

    }

  4. 列表屏幕构建以:

    开头
      @Override
     小部件构建(buildContext上下文){
         返回条件意外popscope(
         OnWillPop:_ONWILLPOP,
         syseaddcallback:widget._haschanges,//< _haschanges是正确的
         孩子:脚手架(
             钥匙:_scaffoldkey,
             ...
     
  5. 使用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.

  1. 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,
         );
    }
    
  2. 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));
       }
    }
    
  3. 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,
             );
    

    }

  4. 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,
             ...
    
  5. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温暖的光 2025-01-30 21:17:39

不确定这是最好的解决方案,但可以正常工作。

@override
Widget build(BuildContext context) {
if (Platform.isAndroid) {
  return ConditionalWillPopScope(
    onWillPop: _onWillPop,
    shouldAddCallback: true,
    child: _buildScaffold(context),
  );
} else {
  //iOS
  return GestureDetector(
    behavior: HitTestBehavior.deferToChild,  // if you have lower level drag/drop widgets
    onHorizontalDragUpdate: (details) {
      if (details.delta.direction >= 0) {
        _onWillPop();
      }
    },
    child: _buildScaffold(context),
  );
}

}

Not sure this is the best solution, but it works.

@override
Widget build(BuildContext context) {
if (Platform.isAndroid) {
  return ConditionalWillPopScope(
    onWillPop: _onWillPop,
    shouldAddCallback: true,
    child: _buildScaffold(context),
  );
} else {
  //iOS
  return GestureDetector(
    behavior: HitTestBehavior.deferToChild,  // if you have lower level drag/drop widgets
    onHorizontalDragUpdate: (details) {
      if (details.delta.direction >= 0) {
        _onWillPop();
      }
    },
    child: _buildScaffold(context),
  );
}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文