在尝试注册用户时出现意外错误?

While trying to register user i'm getting unexpected error?

我的数据库有一个 属性 我命名为 url 。并且我想保护一个用户可以用图片更新的字符串,但这是我的问题。在注册时,我保护包括 url 在内的用户数据。我不让用户上传图片。该过程可以在应用程序内完成。但是要显示默认图片,我必须使用字符串上传 url。我想展示资产图像,但不知道我做错了什么。所以也许任何人都可以提供帮助。

这是我的图片:

assets:
      - assets/profilepictureer.png

属性 因为我想保护路径或其他有意义的东西在数据库中调用“url”。

这是我的注册方法:

 Future signUp(String email, String fullname,String password,String url,String username) async {
    try {
      UserCredential result = await _auth.createUserWithEmailAndPassword(email: email, password: password);
      result.user?.sendEmailVerification();
       User user = result?.user;
      await DatbaseService(uid: user.uid).updateUserData(email, fullname, password,url,username);
      return _userFromFirebaseUser(user);
      //user.sendEmailVerification();
      //( await DatbaseService(uid:user).updateUserData('0','new crew member','100','dfdssf')).user.uid;;
    } on FirebaseAuthException catch (e) {
      switch (e.code) {
        case 'invalid-email':
          {
            return 'Email is not valid';
          }
        case 'user-disabled':
          {
            return 'Account is not active';
          }
        case 'user-not-found':
          {
            return 'No user found';
          }
        case 'wrong-password':
          {
            return 'wrong password';
          }
        default:
          {
            return 'Unexpected error!';
          }
          return null;
      }
    }
  }

下面是我将图片名称上传到 firebase 的方法:

  onPressed: () async {

            if (_formKey.currentState.validate()) {
url=  "image1";
              String authError = await _auth.signUp(email,fullname,password,url,username);
              if (authError != null) {
                setState(() => jawoll = true);
                setState(() => error = authError);
              }else{
                setState(() => loading = true);
                setState(() => jawoll = false);
               Navigator.of(context).pushReplacement(
                    MaterialPageRoute(builder: (context) =>VerifyScreen()));
                setState(() => error = "Email send to $email");

              }
            }
          }),
    );
  }

然后我想在我的方法中像那样使用它:

 String img1= "image1";
  decoration: BoxDecoration(
                              color: Colors.white,
                            ),
                            child: _pickedImage != null
                                ? Image.file(
                              _pickedImage,
                              fit: BoxFit.cover,
                            )
                                : userData.url != null && userData.url != "image1"
                                ? Image.network(
                              userData.url,
                              fit: BoxFit.cover,
                            )
                                : Image.asset('assets/$img1.png'),// Your widget is here when image is no available.
                          ),

                        ),
                        decoration: new BoxDecoration(
                            shape: BoxShape.circle,
                            border:new Border.all(
                                color:Colors.black,
                                width: 5
                            )
                        ),
                  ),

但是在尝试注册用户时我遇到了意外错误控制台看起来像这样:

Performing hot restart...
Syncing files to device sdk gphone x86 arm...
Restarted application in 1.939ms.
W/DynamiteModule(11321): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(11321): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(11321): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/IInputConnectionWrapper(11321): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(11321): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(11321): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(11321): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(11321): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(11321): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(11321): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(11321): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(11321): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(11321): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(11321): setComposingRegion on inactive InputConnection
W/IInputConnectionWrapper(11321): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(11321): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(11321): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(11321): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(11321): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(11321): getTextAfterCursor on inactive InputConnection
W/System  (11321): Ignoring header X-Firebase-Locale because its value was null.

它说忽略 header 这意味着那里没有错误,但为什么我会收到此错误????

除非您事先将他上传到 firebase,否则您无法从资产图像​​轻松创建 url。我建议通过这样的方式在应用程序端处理这个问题

if(firebaseImage != null){
  //if firebase image exists, dislay it
  FirebaseImage(...)
} else {
  //if no image was uloaded yet, show asset placeholder
  AssetImage('assets/profilepictureer.png')
}

如果你的问题是图片资源上传到firebase,你可以关注this tutorial

编辑: 您可以手动上传一次占位符图像,然后在注册期间每次重复使用相同的 url 作为占位符图像 url