Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log中引发的一个空指针异常 #1

Closed
junixapp opened this issue Dec 29, 2020 · 4 comments
Closed

log中引发的一个空指针异常 #1

junixapp opened this issue Dec 29, 2020 · 4 comments

Comments

@junixapp
Copy link

junixapp commented Dec 29, 2020

日志信息:

════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════
The following NoSuchMethodError was thrown while handling a gesture:
The getter 'settings' was called on null.
Receiver: null
Tried calling: settings

When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      LifecycleObserver.didRemove (package:lifecycle/src/lifecycle_observer.dart:197:41)
#2      _NavigatorRemoveObservation.notify (package:flutter/src/widgets/navigator.dart:2679:14)
#3      List.forEach (dart:core-patch/growable_array.dart:313:8)
#4      NavigatorState._flushObserverNotifications (package:flutter/src/widgets/navigator.dart:3303:27)
...
Handler: "onTap"

具体代码定位到:

/// [route] 被移除的route
  /// [previousRoute] 被移除route下面的route,移除多个route时,该参数值不变
  @override
  void didRemove(Route route, Route previousRoute) {
    super.didRemove(route, previousRoute);
    log('LifecycleObserver($hashCode)#didRemove('
        'route: ${route.settings.name}, '
        'previousRoute: ${previousRoute.settings.name})');

    _sendEventToGivenRoute(route, LifecycleEvent.pop);
    if (previousRoute.isCurrent) {
      _sendEventToGivenRoute(previousRoute, LifecycleEvent.active);
    }

    _routes.remove(route);
  }

打印previousRoute.settings.name时报错的。
我的场景是移除所有router然后pushName一个新的就报错了,使用的方法是pushNamedAndRemoveUntil
此时previousRoute是null

flutter版本 1.22.4

我把代码修改为下面这样后就可以了:

 void didRemove(Route route, Route previousRoute) {
    super.didRemove(route, previousRoute);
    log('LifecycleObserver($hashCode)#didRemove('
        'route: ${route?.settings?.name}, '
        'previousRoute: ${previousRoute?.settings?.name})');

    _sendEventToGivenRoute(route, LifecycleEvent.pop);
    if (previousRoute?.isCurrent??false) {
      _sendEventToGivenRoute(previousRoute, LifecycleEvent.active);
    }

    _routes.remove(route);
  }
@chenenyu
Copy link
Owner

谢谢反馈 👍 最晚明天会发一个修复版本

@junixapp
Copy link
Author

@chenenyu 0.1.1版本少加一个地方,目前还是报错:

 @override
  void didRemove(Route route, Route previousRoute) {
    super.didRemove(route, previousRoute);
    log('LifecycleObserver($hashCode)#didRemove('
        'route: ${route?.settings?.name}, '
        'previousRoute: ${previousRoute?.settings?.name})');

    _sendEventToGivenRoute(route, LifecycleEvent.pop);
    if (previousRoute.isCurrent) {
      _sendEventToGivenRoute(previousRoute, LifecycleEvent.active);
    }

    _routes.remove(route);
  }

if判断哪里也要加 ?:

if (previousRoute.isCurrent) {
  _sendEventToGivenRoute(previousRoute, LifecycleEvent.active);
}

应修改为:

if (previousRoute?.isCurrent??false) {
  _sendEventToGivenRoute(previousRoute, LifecycleEvent.active);
}

今天能更新个版本吗,有点着急。。。。

@chenenyu
Copy link
Owner

不好意思 才看到,现在处理下

@chenenyu chenenyu reopened this Dec 30, 2020
@chenenyu
Copy link
Owner

try lifecycle: ^0.1.1+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants