getProductsBySearchText method

Future<PrintifyProductListModel> getProductsBySearchText({
  1. required String baseUrl,
  2. required String searchText,
})

Gets all products with the searchText in the title.

Implementation

Future<PrintifyProductListModel> getProductsBySearchText({
  required String baseUrl,
  required String searchText,
}) async {
  Response? response;

  try {
    final dio = Dio(
      BaseOptions(
        contentType: 'application/json',
        responseType: ResponseType.json,
        baseUrl: 'https://$baseUrl/app',
      ),
    );
    response = await dio.get(
      '/getProductsBySearchText',
      queryParameters: {
        'searchText': searchText,
      },
    );

    if (response.statusCode == 200) {
      return PrintifyProductListModel.fromJson(response.data);
    } else {
      throw Exception(
          'Non 200 code for getting products by search text of $searchText. Response: ${response.statusCode}');
    }
  } catch (e) {
    throw Exception(
        'Non 200 code for getting products by search text of $searchText. Response: ${response?.statusCode}');
  }
}