getStaticValue method

T? getStaticValue()

We need this method to get the value of the delegate if it is a static value. We want to avoid calling the function every time we need the value and we can use this method in init() to get the value of the delegate and store it in a variable.

Example:

class A {
  double? value;
  final StatefulSheetDelegate<T> valueDelegate;

  A({required this.valueDelegate}) {
    value = valueDelegate.getStaticValue();
  }

  ...

  void foo() {
    final z = value ?? valueDelegate.getValue(scrollController) ?? _defaultValue;
  }
}

Implementation

T? getStaticValue() {
  if (this is StatefulSheetDelegateValue<T>) {
    return (this as StatefulSheetDelegateValue<T>).value;
  }
  return null;
}