반응형

 

 Dart에는 code의 주석을 문서로 만들어주는 기능을 가지고 있습니다.

 

project 폴더에서 아래와 같이 dart doc 라고 입력을 하면, 프로젝트 밑에 문서가 생성됩니다.

$ dart doc

 

문서 위치는 아래와 같습니다.

$ ~/[myporject]/doc/api 

 

문서에 설명을 다는 방법은 /// 로 주석을 달아주는 방식입니다.

아래 몇가지 예시를 포함 하였습니다.

 

/// This is a brief description of the library or package.
library my_library;

 

 

/// This is a brief description of the MyClass class.
///
/// Optionally, additional details about the class can be provided.
class MyClass {
 /// This is a constructor for MyClass.
 MyClass();
}

 

 

/// This is a brief description of the function.
///
/// It takes [param1] and [param2] as parameters and returns a String.
String myFunction(int param1, String param2) {
 // …
}

 

 

/// This is a brief description of the field.
int myField;

 

 

/// This is a brief description of the function.
///
/// It takes [param1] and [param2] as parameters and returns a String.
///
/// Additional details can be added, including:
/// - List items
/// - [Links to other elements]
/// - _Italic_ or **bold** text.
String myFunction(int param1, String param2) {
 // …
}

 

 

/// This is a brief description of the function.
///
/// It takes [param1] and [param2] as parameters and returns a String.
///
/// - `param1`: Description of parameter 1.
/// - `param2`: Description of parameter 2.
///
/// Returns a String representing the result.
String myFunction(int param1, String param2) {
 // …
}

 

/// This is a brief description of the MyEnum enum.
enum MyEnum {
 /// Description of EnumValue1.
 EnumValue1,
/// Description of EnumValue2.
 EnumValue2,
}

 

 

/// Represents a user in the system.
class User {
 // …
}

 

 

/// Returns the sum of two integers.
///
/// Example:
/// ```dart
/// int result = add(2, 3); // result will be 5
/// ```
int add(int a, int b) {
  return a + b;
}

 

 

/// Calculates the area of a rectangle.
///
/// [length]: Length of the rectangle.
/// [width]: Width of the rectangle.
///
/// Returns the area as a double.
double calculateArea(double length, double width) {
  return length * width;
}

 

 

/// Finds the maximum value in the given list.
///
/// [numbers]: List of integers.
///
/// Returns the maximum value in the list. Returns null if the list is empty.
///
/// Throws [ArgumentError] if [numbers] is null.
int? findMax(List<int> numbers) {
  // Implementation
}

 

 

/// Represents a configuration for the application.
///
/// See {@link User} for user-related settings.
///
/// For more details, visit the {@linkplain <https://example.com/docs}> documentation.
class AppConfig {
  // ...
}

 

 

 

예시 참고

https://medium.com/@jaitechie05/flutter-and-dart-best-practices-in-documentation-acae6bd7de9b

 

Flutter and Dart: Best Practices in Documentation

DartDoc Best Practices in Documentation.

medium.com

 

+ Recent posts