问题描述
我的数据库有一个我命名为 url 的属性。并且我想保护一个用户可以用图片更新的字符串,但这是我的问题。在注册时我保护了包括 url 在内的用户数据。我不让用户上传图片。该过程可以在应用程序内完成。但是要显示默认图片,我必须上传带有 string 的 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;
}
}
}
onpressed: () async {
if (_formKey.currentState.validate()) {
url= "image1";
String authError = await _auth.signUp(email,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,)
: 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.
它说忽略标题意味着那里没有错误,但为什么我收到这个错误????
解决方法
除非您事先将其上传到 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