RestQueryBuilder<DataType, QueryType extends RestBaseQueryParams, ErrorType> constructor

RestQueryBuilder<DataType, QueryType extends RestBaseQueryParams, ErrorType>({
  1. Key? key,
  2. required BuildContext context,
  3. DataType? initial,
  4. RetryConfig? retryConfig,
  5. RefreshConfig? refreshConfig,
  6. dynamic onData(
    1. dynamic data
    )?,
  7. dynamic onError(
    1. ErrorType
    )?,
  8. bool enabled = true,
  9. required Widget builder(
    1. BuildContext,
    2. Query
    ),
  10. required QueryType params,
})

Implementation

RestQueryBuilder({
  super.key,
  required BuildContext context,
  super.initial,
  super.retryConfig,
  super.refreshConfig,
  Function(dynamic data)? onData,
  Function(ErrorType)? onError,
  super.enabled = true,
  required Widget Function(BuildContext, Query) builder,
  required this.params,
}) : super(
          params.tag,
          () async {
            return await (RestQueryClient.of(context)!.baseQuery)
                .performQuery<QueryType, DataType>(params);
          },
          builder: builder,
          onData: (data) {
            if (onData != null) onData(data);
          },
          jsonConfig: JsonConfig(
            fromJson: (json) {
              var data = json['data'];
              for (var trans in params.transformers) {
                data = trans(data);
              }
              return data;
            },
            toJson: (data) {
              return {'data': data};
            },
          ),
          onError: (error) {
            // dispatch bloc event

            var onErrorGlobal = RestQueryClient.of(context)!.onError;
            if (onErrorGlobal != null) onErrorGlobal(error, null);
            if (onError != null) onError(error);
          });