create<T extends AxelorModel> method

Future<AxelorResult<T>> create<T extends AxelorModel>({
  1. required bool baseDomain,
  2. required String model,
  3. required AxelorMapper<T> mapper,
  4. required AxelorBody body,
  5. String? endPoint,
  6. bool withAuth = true,
  7. Map<String, dynamic>? params,
  8. Map<String, dynamic>? headers,
})

create model in axelor backend

params: baseDomain: boolean flag to detrmine prefix of model if true will generate /com.axelor. + model if false will generate AxelorBuilder.domain + model model: model name in axelor backend endPoint: if no sufficient method provide to create end point, you can provide end point directly withAuth: if true add token in header params: query params headers: http headers mapper: Callback to transform json response into AxelorModel body: AxelorBody new record object

Axelor.create(
  baseDomain: true,
  model: UserModel.modelName,
  mapper: UserModel.fromJson,
  body: const AxelorBody(
    fields: ['name', 'lastName'],
    data: {
      'firstName': 'John',
      'lastName': 'Smith',
      'email': 'j.smith@gmail.com',
    },
  ),
);

Implementation

Future<AxelorResult<T>> create<T extends AxelorModel>({
  required bool baseDomain,
  required String model,
  required AxelorMapper<T> mapper,
  required AxelorBody body,
  String? endPoint,
  bool withAuth = true,
  Map<String, dynamic>? params,
  Map<String, dynamic>? headers,
}) async {
  final Options options = buildHeaders(headers: headers, withAuth: withAuth);
  final String _endPoint =
      endPoint ?? buildAxelorEndPoint(baseDomain: baseDomain, model: model, id: null, action: null);

  final Response response = await client.post(
    _endPoint,
    queryParameters: params,
    options: options,
    data: body.toJson(),
  );

  return handleResponse<T>(response, AxelorListModel.fromJsonAsSingle<T>(mapper));
}