getWidgets method

Future<List<WidgetEntry>> getWidgets({
  1. String? userId,
})

Fetch all widgets, optionally filtered by user.

Implementation

Future<List<WidgetEntry>> getWidgets({String? userId}) async {
  final uri = Uri.parse('$baseUrl/api/widgets').replace(
    queryParameters: userId != null ? {'user_id': userId} : null,
  );
  final response = await _client.get(uri);
  _checkResponse(response);

  final data = json.decode(response.body) as Map<String, dynamic>;
  return WidgetResponse.fromJson(data).widgets;
}