of<T extends ServiceState> static method

T of<T extends ServiceState>(
  1. BuildContext context
)

type belirtilmezse bir üsttekini getirir type belirtilirse ve bir üstteki o type değilse üst ağaçtan o servisi bulur

Implementation

static T of<T extends ServiceState>(BuildContext context) {
  var serviceBinding = context.owner;
  if (serviceBinding is StatefulBinding &&
      (serviceBinding as StatefulBinding).state is T) {
    return (serviceBinding as StatefulBinding).state as T;
  } else {
    var serviceComponent = context.findAncestorStateOfType<T>();

    if (serviceComponent == null) {
      throw Exception("No $T found of binding tree");
    }
    return serviceComponent;
  }
}