반응형
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
'Dart,Flutter' 카테고리의 다른 글
[Flutter] freezed 로 json 다루기 (0) | 2024.09.12 |
---|---|
[Flutter] 유용한 위젯들 (0) | 2024.07.30 |
[Flutter] 2024년 새해 계획을 위해서 Todo 앱을 만들어 봤습니다. (1) | 2024.01.11 |
[Flutter] ListView 를 SingleChildScrollView 에서 사용하기 (0) | 2023.12.28 |
[Flutter] 빌드시 플렛폼 추가하기 (1) | 2023.12.28 |