PopscopeIos class

iOS 左滑返回手势拦截插件

该插件用于拦截 iOS 系统的左滑返回手势(interactivePopGesture), 支持三种使用方式:

  1. 推荐:使用 PlatformPopScope widget,自动处理初始化和销毁
  2. 推荐:使用 IosNavigatorKeyInterceptor widget,在组件级别管理 setNavigatorKey
  3. 自动处理:通过 setNavigatorKey 设置 Navigator,插件自动调用 maybePop()(不推荐全局设置)
  4. 业务自定义:通过 setOnLeftBackGesture 设置回调,由业务层自行处理(不推荐全局设置)

强烈推荐使用组件方式(PlatformPopScopeIosNavigatorKeyInterceptor, 它们会自动处理资源管理和生命周期,避免全局配置导致的问题(如多次 pop)。

⚠️ 警告:直接在 main() 中全局设置 setNavigatorKeysetOnLeftBackGesture 可能导致多个页面同时响应返回手势,造成多次 pop 的问题。 建议使用组件方式,在需要处理的页面中包裹相应的 widget。

Constructors

PopscopeIos()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

getPlatformVersion() Future<String?>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

registerPopGestureCallback(VoidCallback callback, BuildContext context) → void
注册左滑返回手势的回调函数
setNavigatorKey(GlobalKey<NavigatorState>? navigatorKey, {bool autoHandle = true}) → void
设置 Navigator Key,用于自动处理页面返回
setOnLeftBackGesture(VoidCallback? callback) → void
设置左滑返回手势的回调函数
unregisterPopGestureCallback(BuildContext context) → void
注销左滑返回手势的回调函数