【发布时间】:2020-04-01 20:19:27
【问题描述】:
我有 4 个类 SignUp 、 Auth、 PageOne 和 InWidget(继承的小部件)。在 classe signUpState 中,我有一个可以使用控制器控制的 swiper。
注册
class SignUp extends StatefulWidget {
static const String id = 'history_page';
@override
SignUpState createState() => SignUpState();
goto(bool x) => createState().goto(x);
}
注册状态
class SignUpState extends State<SignUp> {
SwiperController _swOneCtrl;
@override
void initState() {
_swOneCtrl = new SwiperController();
super.initState();
}
goto(bool anim){
_swOneCtrl.next(animation: anim);
print("goto fired");
}
}
授权
class Auth extends StatelessWidget {
SignUp s = SignUp();
verifyPhoneNumber() {
s.goto(true);
}
}
一页
class PageOneState extends State<PageOne> {
@override
Widget build(BuildContext context) {
final MyInheritedWidgetState state = MyInheritedWidget.of(context);
return RaisedButton(
color: Colors.blueGrey,
disabledColor: Colors.grey[100],
textColor: Colors.white,
elevation: 0,
onPressed: !phonebtn
? null
: () {
final MyInheritedWidgetState state =
MyInheritedWidget.of(context);
state.verifyPhoneNumber();
},
child: Text("CONTINUER"),
),
);
}
}
问题是我想从 auth 调用 verifyPhoneNumber(),它将使用 inwidget 作为中介从 pageone 调用 goto() 方法,但我收到此错误:
Unhandled Exception: NoSuchMethodError: The method 'next' was called on null.
你知道为什么吗?
【问题讨论】:
标签: flutter swiper unhandled-exception