1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Flutter】The getter ‘uid’ isn’t defined for the class 'クラス名'の解消法

Last updated at Posted at 2020-03-12

Firebaseと連携させてサインアップページを作ってるときに出たエラー。

onPressed: () {
                      if (_registerFormKey.currentState.validate()) {
                          FirebaseAuth.instance
                            .createUserWithEmailAndPassword(
                              email: emailInputController.text,
                              password: pwdInputController.text)
                            .then((currentUser) => Firestore.instance
                              .collection("users")
                              .document(currentUser.uid)
                              .setData({
                                "uid": currentUser.uid,
                                "name": nameInputController.text,
                                "email": emailInputController.text,
                              })
                            .then((result) => {
                              Navigator.pushAndRemoveUntil(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => HomePage(
                                            uid: currentUser.uid,
                                          )),
                                  (_) => false),
                                    nameInputController.clear(),
                                    emailInputController.clear(),
                                    pwdInputController.clear(),
                                  })
                              .catchError((err) => print(err)))
                          .catchError((err) => print(err));
                      }
                    },

The getter ‘uid’ isn’t defined for the class ‘AuthResult’.

uidがAuthResultクラスに定義されていないと。

これはAPIのバージョンの問題っぽいです。

そんでもって、今のサインインメソッドはFirebaseUserの代わりにAuthResultを返すので、uidの前にuserを置かないといけないらしいです。

currentUser.uidcurrentUser.user.uidに変更します。

onPressed: () {
                      if (_registerFormKey.currentState.validate()) {
                          FirebaseAuth.instance
                            .createUserWithEmailAndPassword(
                              email: emailInputController.text,
                              password: pwdInputController.text)
                            .then((currentUser) => Firestore.instance
                              .collection("users")
                              .document(currentUser.user.uid)
                              .setData({
                                "uid": currentUser.user.uid,
                                "name": nameInputController.text,
                                "email": emailInputController.text,
                              })
                            .then((result) => {
                              Navigator.pushAndRemoveUntil(
                                  context,
                                  MaterialPageRoute(
                                      builder: (context) => HomePage(
                                            uid: currentUser.user.uid,
                                          )),
                                  (_) => false),
                                    nameInputController.clear(),
                                    emailInputController.clear(),
                                    pwdInputController.clear(),
                                  })
                              .catchError((err) => print(err)))
                          .catchError((err) => print(err));
                      }
                    },

これで解消されました。

参照: https://medium.com/p/556cf6f9ef83/responses/show

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?