createDataModelResponse method

void createDataModelResponse(
  1. String pathPage,
  2. String pageName,
  3. String apiName
)

Implementation

void createDataModelResponse(
  String pathPage,
  String pageName,
  String apiName,
) {
  final apiClassName = apiName.pascalCase;

  final path = join(pathPage, 'data', 'models', 'response');
  DirectoryHelper.createDir(path);
  join(path, '${apiName}_response.dart').write('''import 'dart:convert';

import 'package:core/core.dart';

class ${apiClassName}Response extends Equatable {
const ${apiClassName}Response({
  required this.token,
});

final String token;

Map<String, dynamic> toMap() {
  return {
    'token': token,
  };
}

factory ${apiClassName}Response.fromMap(Map<String, dynamic> map) {
  return ${apiClassName}Response(
    token: map['token'] ?? '',
  );
}

String toJson() => json.encode(toMap());

factory ${apiClassName}Response.fromJson(String source) =>
    ${apiClassName}Response.fromMap(json.decode(source));

@override
List<Object?> get props => [token];
}''');

  StatusHelper.generated(join(path, '${apiName}_response.dart'));
}