invoke method

  1. @override
String invoke(
  1. String method,
  2. dynamic params,
  3. InvokeModuleCallback callback
)
override

Implementation

@override
String invoke(String method, params, InvokeModuleCallback callback) {
  switch (method) {
    case 'getItem':
      AsyncStorageModule.getItem(params).then((String? value) {
        callback(data: value ?? '');
      }).catchError((e, stack) {
        callback(error: '$e\n$stack');
      });
      break;
    case 'setItem':
      String key = params[0];
      String value = params[1];
      AsyncStorageModule.setItem(key, value).then((bool isSuccess) {
        callback(data: isSuccess.toString());
      }).catchError((e, stack) {
        callback(error: 'Error: $e\n$stack');
      });
      break;
    case 'removeItem':
      AsyncStorageModule.removeItem(params).then((bool isSuccess) {
        callback(data: isSuccess.toString());
      }).catchError((e, stack) {
        callback(error: 'Error: $e\n$stack');
      });
      break;
    case 'getAllKeys':
      AsyncStorageModule.getAllKeys().then((Set<String> set) {
        List<String> list = List.from(set);
        callback(data: list);
      }).catchError((e, stack) {
        callback(error: 'Error: $e\n$stack');
      });
      break;
    case 'clear':
      AsyncStorageModule.clear().then((bool isSuccess) {
        callback(data: isSuccess.toString());
      }).catchError((e, stack) {
        callback(error: 'Error: $e\n$stack');
      });
      break;
    case 'length':
      AsyncStorageModule.length().then((int length) {
        callback(data: length);
      }).catchError((e, stack) {
        callback(error: 'Error: $e\n$stack');
      });
      break;
    default:
      throw Exception('AsyncStorage: Unknown method $method');
  }

  return '';
}