runWithStyleOverride<T> static method

Future<T> runWithStyleOverride<T>(
  1. DraftModePlatformStyle style,
  2. FutureOr<T> action()
)

Executes action with a temporary style override.

This is intended for tests and low-level framework wiring where a widget subtree is not the right tool.

Implementation

static Future<T> runWithStyleOverride<T>(
  DraftModePlatformStyle style,
  FutureOr<T> Function() action,
) async {
  final DraftModePlatformStyle? previous = _debugStyleOverride;
  _debugStyleOverride = style;
  try {
    return await action();
  } finally {
    _debugStyleOverride = previous;
  }
}