如何从Firebase存储中检索元数据?

问题描述 投票:0回答:1
info(String choice) async {
    print(choice);
    if (choice == 'Created on') {
      print('hii');
      StorageReference imageRef = storageRef.child(imageLocation);
      await imageRef
          .getMetadata()
          .then((value) => print(value.creationTimeMillis));
      int created = 3;
      String create = timeago.format(
        DateTime.fromMillisecondsSinceEpoch(created),
      );

      print(create);
    }
    Scaffold.of(context).showSnackBar(
      SnackBar(
        content: Text(" hiii"),
      ),
    );
  }

我已经使用了这种方法,但是它似乎不起作用上面的方法是什么]

flutter dart firebase-storage flutter-state
1个回答
0
投票

我认为您正在寻找这个:

StorageReference imageRef = storageRef.child(imageLocation);
imageRef
    .getMetadata()
    .then((value) => {
        String create = timeago.format(
          DateTime.fromMillisecondsSinceEpoch(value.creationTimeMillis),
        );
        print(create);
    })

需要元数据的所有代码都必须在then块中。


或者,如果您想使用await,则不需要then()

StorageReference imageRef = storageRef.child(imageLocation);
var value = await imageRef.getMetadata()
String create = timeago.format(
  DateTime.fromMillisecondsSinceEpoch(value.creationTimeMillis),
);
print(create);
© www.soinside.com 2019 - 2024. All rights reserved.