setUserDataDateTime static method

Future<void> setUserDataDateTime(
  1. String key,
  2. DateTime? value
)

Sets a key-value pair identifier that will be included in all snapshots. This identifier can be used to add the DateTime types.

The key must be unique across your application. The key namespace is distinct for each user data type. Re-using the same key overwrites the previous value. The key is limited to maxUserDataStringLength characters.

A value of null will clear the data. The value is also limited to maxUserDataStringLength characters.

This information is not persisted across application runs. Once the application is destroyed, user data is cleared.

Data can be removed via removeUserDataDateTime.

Method might throw Exception.

Implementation

static Future<void> setUserDataDateTime(
  String key,
  DateTime? value,
) async {
  try {
    if (value == null) {
      removeUserDataDateTime(key);
      return;
    }

    final arguments = {"key": key, "value": value.millisecondsSinceEpoch};
    await channel.invokeMethod<void>('setUserDataDate', arguments);
  } on PlatformException catch (e) {
    throw Exception(e.details);
  }
}