【发布时间】:2020-10-28 13:01:58
【问题描述】:
我最终使用了一个静态函数,但我需要进行导航,它给了我一个错误,即没有为上下文找到 getter,所以我寻找解决方案并找到了 GET 包,但是当我尝试使用它时它给出了我的另一个错误:
E/flutter ( 6078): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)]
Unhandled Exception: NoSuchMethodError: The method 'push' was called on null.
我的代码:
void main() {
runApp(MyApp());
_MyAppState.autologin();
}
class _MyAppState extends State<MyApp> {
static autologin() async {
var userType;
var store = Firestore.instance;
var auth = FirebaseAuth.instance;
final FirebaseUser user = await auth.currentUser();
store.collection('Users').document(user.uid).get().then((value) {
userType = (value.data)['userType'];
if (userType == 'Student') {
Get.to(StudentsPage());
} else if (userType == 'Teacher') {
} else if (userType == 'Admin') {}
});
}
【问题讨论】:
标签: flutter navigation android-context