makeStatelessWidget static method

Future<void> makeStatelessWidget(
  1. String className,
  2. String value, {
  3. String folderPath = widgetsFolder,
  4. bool forceCreate = false,
  5. String? creationPath,
})

Creates a new Stateless Widget.

Implementation

static Future<void> makeStatelessWidget(
  String className,
  String value, {
  String folderPath = widgetsFolder,
  bool forceCreate = false,
  String? creationPath,
}) async {
  String name = className.replaceAll(RegExp(r'(_?widget)'), "");
  ReCase nameReCase = ReCase(name);

  // create missing directories in the project
  await _makeDirectory(folderPath);
  await createDirectoriesFromCreationPath(creationPath, folderPath);

  // create file path
  String filePath = createPathForDartFile(
    folderPath: folderPath,
    className: name,
    prefix: "widget",
    creationPath: creationPath,
  );

  await _checkIfFileExists(filePath, shouldForceCreate: forceCreate);
  await _createNewFile(
    filePath,
    value,
    onSuccess: () {
      final linkText = nameReCase.snakeCase;
      final link = MetroConsole.hyperlink(linkText, filePath);
      MetroConsole.writeInGreen('[Stateless Widget] $link created 🎉');
    },
  );
}