Und*_*doX 1 android dart firebase flutter firebase-storage
我是新手。我尝试使应用程序使用颤振上传一些图像。我已经成功地从图像选择器中选择了一些图像,但是当我尝试将数据写入 Firebase 存储时,只有一张图像成功上传。这是我的代码:
List<File> _imageList = [];
File _image;
Future uploadFile() async {
final FirebaseUser user = await FirebaseAuth.instance.currentUser();
final userId = user.uid;
final StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child(userId).child('images');
final StorageUploadTask task = firebaseStorageRef.putFile(_image);
return task;
}
Run Code Online (Sandbox Code Playgroud)
这是我选择和显示图像的代码
Future getImageFromGallery() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
_imageList.add(_image);
});
}
List<Widget> builtImageDisplay() {
return [
Padding(
padding: const EdgeInsets.all(8.0),
child: new Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: _imageList.length == 0
? new Image.asset('assets/images/format.jpg')
: GridView.count(
shrinkWrap: true,
primary: false,
crossAxisCount: 4,
mainAxisSpacing: 5.0,
crossAxisSpacing: 5.0,
children: _imageList.map((File file) {
return GestureDetector(
onTap: () {},
child: new GridTile(
child: new Image.file(
file,
fit: BoxFit.cover,
),
),
);
}).toList(),
),
),
),
)
];
}
Run Code Online (Sandbox Code Playgroud)
简单function上传多个图像文件。
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
Future<Null> _uploadImages() async {
_imageList.forEach((f) {
final StorageReference _ref = storageImageRef.child(basename(f.path));
final StorageUploadTask uploadTask = _ref.putFile(f);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4346 次 |
| 最近记录: |