useAndDisposeInstance<T extends MvvmInstance> method

Future useAndDisposeInstance<T extends MvvmInstance>(
  1. Future body(
    1. T
    )
)

Helper method to get unique instance and dispose it automatically after body is finished

body - function to run this this instance

Implementation

Future useAndDisposeInstance<T extends MvvmInstance>(
  Future Function(T) body,
) async {
  final instance = getUnique<T>();

  final result = await body(instance);

  instance.dispose();

  return result;
}