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

auto_route中创建多个router使用nested router时,navigatorObservers添加FlutterSmartDialog.observer报错 #132

Closed
Dean-Spotec opened this issue Jun 3, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@Dean-Spotec
Copy link

版本信息

  • Flutter版本:[v3.7.12]
  • flutter_smart_dialog版本:[v4.8.2+4]

描述bug/需求

报错:Failed assertion: line 3299 pos 14: 'observer.navigator == null': is not true.
auto_route文档中描述:使用nested router时,必须每次创建新的observer。是否可以暴露SmartNavigatorObserver出来,让我们直接使用:

return MaterialApp.router(                
  routerConfig: _appRouter.config(                         
    navigatorObservers: () => [SmartNavigatorObserver()],                
  ),                  
);

Then we pass our observer to the .config(). Important notice that navigatorObservers property is a builder function that returns a list of observes and the reason for that is a navigator observer instance can only be used by a single router, so unless you're using a one single router or you don't want your nested routers to inherit observers make sure navigatorObservers builder always returns fresh observer instances.

@xdd666t
Copy link
Member

xdd666t commented Jun 4, 2023

@xdd666t xdd666t self-assigned this Jun 4, 2023
@xdd666t xdd666t added the unread document Documentation explained, unread documentation label Jun 4, 2023
@Dean-Spotec
Copy link
Author

Dean-Spotec commented Jun 5, 2023

现在项目中就是使用的FlutterSmartDialog.observer然后报错,需求是想实现类似iOS中present一个模块的功能:

2023-06-05.15.47.31.mov

想要这种效果,就需要用到auto_route中的nested router,用了nested router则navigatorObservers必须每次都得新建,不能用静态变量或者存储下来的属性。
image
我写了一个demo,大佬有空可以看下:
smart_auto.zip

xdd666t added a commit that referenced this issue Jun 5, 2023
@xdd666t
Copy link
Member

xdd666t commented Jun 5, 2023

  • 试下新版本,还是用 FlutterSmartDialog.observer
dependencies:
  flutter_smart_dialog: ^4.9.1

@xdd666t xdd666t added enhancement New feature or request and removed unread document Documentation explained, unread documentation labels Jun 5, 2023
@Dean-Spotec
Copy link
Author

大佬神速,🥹

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

No branches or pull requests

2 participants