Я пытаюсь получить имя, описание, цену и фотографию объекта и сохранить его в базе данных.У меня также есть проблема с сохранением фотографии в хранилище: при первом запуске программы и добавлении фотографии она сохраняется с именем создателя
wordPair.asPascalCase;
затем программа получает URL этой фотографии и сохраняет ее в базе данных, но когда я добавляю вторую фотографию, эта фотография получает имя старой фотографии, а новая фотография заменяет старую фотографию в базе данных (из-занеправильное имя).
Где ошибка?Как я могу создать новую фотографию после того, как я уже загрузил другую фотографию?
File sampleImage;
Future getImage() async {
var tempImage = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
sampleImage = tempImage;
addDialog(context);
}); }
photoProd() {
if (sampleImage != null) {
return FileImage(sampleImage);
} else
return ExactAssetImage('images/person.jpg'); }
Future getUrl(name) async {
final ref = FirebaseStorage.instance.ref().child(name);
var url = await ref.getDownloadURL();
this.photoUrl = url;
print(name);
//name = wordPair.asPascalCase;
name = null;
//name = null;
}
final wordPair = WordPair.random(); Future<bool> addDialog(BuildContext context) async {
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Add Tiket', style: TextStyle(fontSize: 15.0)),
content: Column(
children: <Widget>[
Column(children: <Widget>[
IconButton(
iconSize: 175,
color: Colors.red,
icon: CircleAvatar(
backgroundImage: photoProd(),
radius: 125,
),
onPressed: () {
getImage();
},
),
IconButton(
icon: Icon(
Icons.add_a_photo,
size: 30,
color: Colors.red,
),
onPressed: () {
//String name;
var name = wordPair.asPascalCase;
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child(name);
final StorageUploadTask task =
firebaseStorageRef.putFile(sampleImage);
getUrl(name);
},
),
]),
TextField(
decoration: InputDecoration(hintText: 'Enter product Name'),
onChanged: (value) {
this.product = value;
},
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(hintText: 'Enter description'),
onChanged: (value) {
this.description = value;
},
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(hintText: 'Enter product price'),
onChanged: (value) {
this.price = value;
},
),
],
),
actions: <Widget>[
FlatButton(
child: Text('Add'),
textColor: Color(0xffd50000),
onPressed: () {
sampleImage = null;
Navigator.of(context).pop();
crudObj.addData({
'productName': this.product,
'description': this.description,
'photoUrl': this.photoUrl,
'price': this.price,
}).catchError((e) {
print(e);
});
},
)
],
);
}); }
Спасибо за помощь !!!