HiNavigator.getInstance().registerRouteJump没有生效
来源:1-2 课程导学
慕田峪6597705
2022-05-26
这是5-9的代码,我专门仿写了一段代码测试了一下
class A extends _B {
B? b;
A._();
static A? _instance;
static A getInstance() {
if (_instance == null) {
return A._();
}
return _instance!;
}
void registerB(B b) {
LogUtil.e(b, tag: "A test");
this.b = b;
LogUtil.e(this.b, tag: "A test");
}
@override
void onJumpTo() {
b?.onJumpTo();
}
}
abstract class _B {
void onJumpTo();
}
class B {
final VoidCallback onJumpTo;
B({required this.onJumpTo});
}
为什么registerB不成功呢,调用代码如下:
A.getInstance().registerB(B(onJumpTo: () {}));
LogUtil.e(A.getInstance().b, tag: "test");
明明前面有调用registerB,结果A中成员b仍是null
打印结果如下:可见registerB没有成功
I/flutter (28335): A test e Instance of 'B'
I/flutter (28335): A test e Instance of 'B'
I/flutter (28335): test e null
老师看下我的代码哪里面有问题
写回答
1回答
-
CrazyCodeBoy
2022-05-26
但看代码没看出问题来,你debug打断点一步步追踪调试下看看问题出在哪里呢012022-06-06
相似问题