简体   繁体   English

Flutter auto_route,在 null 上调用了 getter 'key'

[英]Flutter auto_route, getter 'key' was called on null

import 'package:myapp/core/routes/router.gr.dart' as app_router;

child: MaterialApp(
    title: 'MyApp',
    debugShowCheckedModeBanner: false,
    builder: ExtendedNavigator.builder<app_router.Router>(
      router: app_router.Router()
    ),

I have implememented autoroute however I get an error here that the getter key was called on null我已经实现了自动路由,但是我在这里收到一个错误,即在 null 上调用了 getter 键

The problem is here is this line (line 37).问题在这里是这一行(第 37 行)。

key: GlobalObjectKey(nav.key),

Commenting out the line from library works fine for me.注释掉库中的行对我来说很好用。 It may be a temporary problem.这可能是一个暂时的问题。

As Masnun pointed out, commenting out the line 37 solves the issue.正如 Masnun 所指出的,注释掉第 37 行可以解决这个问题。 However, there is a different solution that doesn't involve touching the source of the auto_route.但是,有一种不同的解决方案不涉及接触 auto_route 的源。

I fixed this issue by removing .builder from:我通过从以下位置删除.builder解决了这个问题:

builder: ExtendedNavigator.builder(
  router: Router(),
  ...
),

and changed to并改为

builder: ExtendedNavigator(
  router: Router(),
  ...
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM