Skip to main content
Dart explicitly forbids the application of the async modifier to getters. A getter, defined using the get keyword, must execute synchronously and return a value immediately. While a getter may define a return type of Future<T>, the body of the getter cannot utilize the await keyword to suspend execution or unwrap asynchronous results.

Syntax Restrictions

Attempting to mark a getter as async results in a compile-time error.
class DataProvider {
  // ⛔️ COMPILE ERROR: Getters cannot be async
  Future<String> get data async {
    await Future.delayed(Duration(seconds: 1));
    return 'Data';
  }
}

Valid Patterns

To expose asynchronous data or operations, developers must choose between returning a Future synchronously or converting the getter into a method.

1. Getter Returning a Future

A getter can return a Future<T>, but the construction of that Future must happen synchronously within the block. This is often used for chaining existing Futures without pausing execution.
class DataProvider {
  final Future<String> _pendingRequest;

  DataProvider(this._pendingRequest);

  // ✅ VALID: Returns a Future object synchronously
  Future<String> get data {
    return _pendingRequest.then((val) => val.toUpperCase());
  }
}

2. Asynchronous Method

If the logic requires the await keyword to pause execution (e.g., for sequential asynchronous operations), the member must be defined as a method rather than a getter.
class DataProvider {
  // ✅ VALID: Methods can be async
  Future<String> fetchData() async {
    await Future.delayed(Duration(seconds: 1));
    return 'Data';
  }
}

Technical Distinction

  • Getters (get): Imply lightweight, constant-time, or immediate access to a property. The Dart language specification enforces synchronous execution to align with the semantic expectation that property access does not block or suspend.
  • Methods (()): Imply an operation or computation that may involve significant processing or latency, making them the required construct for async/await logic.
Master Dart with Deep Grasping Methodology!Learn More