loader abstract method

Future<PageResponse<T>> loader(
  1. PageRequest request
)

Loads data for this page.

This method is called before rendering and should return either:

The loader can perform async operations like fetching from APIs, reading from databases, making HTTP requests, etc.

Example

@override
Future<PageResponse<User>> loader(PageRequest request) async {
  final userId = request.pathParamInt('id');

  // Fetch from external API
  final response = await http.get(Uri.parse('$apiUrl/users/$userId'));
  if (response.statusCode == 404) {
    return PageRedirect('/404');
  }

  final user = User.fromJson(jsonDecode(response.body));
  return PageData(user);
}

Implementation

Future<PageResponse<T>> loader(PageRequest request);