init method

Future<void> init()

Implementation

Future<void> init() async =>
    await Hive.openBox<String>(_USER_TELEMETRY_BOX_NAME)
        .then((Box<String> e) {
      userPrefsTelemetryBox = e;
      Debug().info(
          "Loading User Telemetry. Box content is: ${userPrefsTelemetryBox.values.toString()}");
      if (!userPrefsTelemetryBox.containsKey(userDBName)) {
        Debug()
            .warn("COULD NOT FIND USER_PREFS, CREATING NEW MODEL");
        reset();
        save();
      } else {
        Debug().info("FOUND USER_PREFS, LOADING MODEL");
        _currentModel = UserPrefModel.fromJson(
            jsonDecode(userPrefsTelemetryBox.get(userDBName)!));
      }
      Debug().warn(
          "Loaded the following contents for USER_PREF: ${_currentModel.toJson().toString()}");
      Timer.periodic(
          const Duration(seconds: Shared.USER_TELEMETRY_SAVE_CYCLE),
          (Timer _) async => await save());
    });