addNewWProfile function

Future<bool> addNewWProfile(
  1. BuildContext context,
  2. WidgetRef ref,
  3. String text
)

Implementation

Future<bool> addNewWProfile(
    BuildContext context, WidgetRef ref, String text) async {
  try {
    final res = await ref.read(workerKeysProvider).add(
          WorkerKey.fromJson(
            jsonDecode(text) as Map<String, dynamic>,
          ),
        );
    if (!res) {
      showErrorNotification(
        tr().cantAddDepDuplicate,
      );
      if (context.mounted) {
        FocusScope.of(context).requestFocus(
          FocusNode(),
        );
      }

      return true;
    }
  } on FormatException {
    showErrorNotification(
      tr().cantAddDepBadFormat,
    );
    if (context.mounted) {
      FocusScope.of(context).requestFocus(
        FocusNode(),
      );
    }
  }

  return false;
}