PrefItem<T> constructor

PrefItem<T>(
  1. PrefsStorage storage,
  2. String key, {
  3. T initFunc()?,
  4. CheckValueFunc<T?>? checkValue,
})

Implementation

PrefItem(
  this.storage,
  this.key, {
  T Function()? initFunc,
  this.checkValue,
}) {
  if (T == int) {
    this._type = ItemType.int;
  } else if (T == String) {
    this._type = ItemType.string;
  } else if (T == double) {
    this._type = ItemType.double;
  } else if (T == bool) {
    this._type = ItemType.bool;
  } else if (T.toString() == 'List<String>') {
    this._type = ItemType.stringList;
  } else if (T == DateTime) {
    this._type = ItemType.dateTime;
  } else {
    throw TypeError();
  }

  this._initCompleter = Completer<PrefItem<T>>();
  this._initCompleteFuture = this._initCompleter.future;

  if (initFunc != null) {
    this._init(initFunc);
  } else {
    this.read();
  }
}