RollingGlory is Company or Creative Digital Media studio based in Bandung, Indonesia.
GloryConventionLint is code judgment for Convention Lint Flutter support IDE Android Studio/Visual Studio Code.
- add glory_convention_lint into
package.yaml
$ flutter pub add --dev glory_convention_lint
dev_dependencies:
glory_convention_lint: ^1.0.0
custom_lint: ^0.2.5
- add plugin analyzer into
analysis_options.yaml
analyzer:
plugins:
- custom_lint
- Model class name convention
- Model file name convention
- Model annotation convention
- Prefer nullable for models convention
- Naming Convention
- Prefer single class per file convention
- Prefer static const lang variable convention
- Base response import convention
- One variable for lang convention
- Model class name convention example
- Model file name convention example
- Model annotation convention example
- Prefer nullable for models convention example
- Service class name convention example
- Service file name convention example
- Service annotation convention example
Ensure to add Model word at the end of class name in models file
//DO
class ProductModel {}
//DON'T
class Model {}
The file name for models must end with _model.dart
//DO
product_model.dart
//DON'T
product.dart
productmodel.dart
Model file must always be put inside of model directory.
|- data
|- network
|- models
Add @JsonSerializable() from Retrofit to above your class model name
//DO
@JsonSerializable()
class ProductModel {
int? id;
}
//DON'T
class ProductModel {
int? id;
}
@JsonSerializable()
Fields of Model class is preferable to have nullable field. example : String? instead of String
//DO
class Product {
String? name;
Product({this.name});
}
//DON'T
class Product {
String name;
Product({this.name});
}
Ensure to add Services word at the end of class name in models file
//DO
class GiftServices{}
class ProductServices{}
//DON'T
class Gift{}
class ProductService{} // singular instead of plural
The file name for services must end with service.dart
//DO
gift_services.dart
product_services.dart
//DON'T
product_service.dart //singular instead of plural
ProductRequest.dart
Service file must always be put inside of services directory.
|- data
|- network
|- services
Add @RestApi() from Retrofit to above your class service name
//DO
@RestApi() //RestApi Annotation is added
abstract class ProductServices {}
//DON'T
//Forget to add RestApi Annotation
abstract class ProductServices {}
Ensure to add Enum word at the end of enum class name in the file.
//DO
enum AvatarEnum {}
//DON'T
enum EnumAvatar {}
Ensure to add _enum.dart prefix at the end of file name.
//DO
gift_enum.dart
product_enum.dart
//DON'T
ProductEnum.dart
Enum file must always be put inside of enum directory or network enum directory.
//Network enum directory
|- data
|- network
|- enums
//Enum directory
|- data
|- enums
Request class always end with "Request", and must use PascalCase.
//DO
class GiftRequest{}
class ProductRequest{}
//DON'T
class Gift{}
class product_request{}
Request file must always end with "_request" and should always use snake_case for file naming.
//DO
product_request.dart
//DON'T
ProductRequest.dart
Request file must always be put inside of request directory.
|- data
|- network
|- request
Response class always end with "Response", and must use PascalCase.
//DO
class GiftResponse{}
class ProductResponse{}
//DON'T
class Gift{}
class product_response{}
Response file must always end with "_response" and should always use snake_case for file naming.
//DO
product_response.dart
//DON'T
ProductResponse.dart
Response file must always be put inside of response directory.
|- data
|- network
|- response
PascalCase | CamelCase | Plural | SnakeCase | Examples | |
Class | ✅ | class ModelResponse{} | |||
Service Class | ✅ | ✅ | class ModelServices{} | ||
Constant Class | ✅ | ✅ | class NetworkConstants{} | ||
Extension | ✅ | ✅ | extension StringExtensions on String | ||
Field | ✅ | int id; | |||
Variable | ✅ | int variable; | |||
Local variable | ✅ | ✅ | int _variable; | ||
Parameter | ✅ | String param | |||
Method | ✅ | void methodName(){} | |||
Local Method | ✅ | ✅ | void _methodName(){} | ||
Enum Type | ✅ | enum Status{} |
Avoid Declaring multiple classes in one file. It is best practice to declare one class in one file instead of multiple of class in one files, to reduce confusion.
//DO
-- test.dart --
class One = {};
//DON'T
-- test.dart --
class One = {};
class Two = {};
Declare variable as static const.
//DO
class One {
static const variableOne = "Value"
}
//DON'T
class One {
String variableOne = "Value";
}
Both BaseResponse and BaseListResponse must be implemented and imported from rollingglory_codebase When an application communicates to the backend via API calls, we usually receive two type of responses. single object and multi objects. both types need to be implemented in service file, the service file is actually an abstract class that contains a set of methods which is needed in order to get data from API.
//DO
class One {
Future<BaseListResponse<Episode>> getEpisodes();
Future<BaseResponse<Episode>> getEpisodeDetail();
}
//DON'T
class One {
Future<Episode> myMethod();
}
Ensure to separate the variable that represents a language, one class is supposed to have one variable.
//DO
-- languages/id_lang.dart --
Map<String,String> id = {};
-- languages/en_lang.dart --
Map<String,String> en = {};
//DON'T
-- languages.dart --
Map<String,String> id = {};
Map<String,String> en = {};
You can follow us at https://rollingglory.com/