[Dart/Linter] Dart Singleton 클래스 형식 > Flutter/Dart/Node

본문 바로가기
사이트 내 전체검색

Flutter/Dart/Node

[Dart/Linter] Dart Singleton 클래스 형식

페이지 정보

작성자 sbLAB 댓글 0건 조회 2,856회 작성일 23-01-08 20:22

본문

[Linter 참고]

Dart 는 변수명에 언더스코어(_) 붙혀(_instanceprivate 을 정의하고, IDE툴은 private 에 대해 final 제안.

private / final =>  _instance  

public =>  instance   

https://dart-lang.github.io/linter/lints/prefer_final_fields.html 



UserInfoModelRepository  Singleton 클래스 만들기 


1) 컨트롤러등에서 데이타 변경필요한 경우 

※  final   _instance  => instance 


class UserInfoModelRepository {

static UserInfoModelRepository instance = UserInfoModelRepository._internal();

factory UserInfoModelRepository() {
return instance;
}

UserInfoModelRepository._internal();
} 


2) 데이타 변경 없거나, 변경되면 안되는 경우 

※  final   instance  =>  _instance [권장 Linter Rules]   


class UserInfoModelRepository {

static final UserInfoModelRepository _instance = UserInfoModelRepository._internal();

factory UserInfoModelRepository() {
return _instance;
}

UserInfoModelRepository._internal();
} 


댓글목록

등록된 댓글이 없습니다.

회원로그인

접속자집계

오늘
287
어제
376
최대
1,279
전체
220,641

그누보드5
Copyright © sebom.com All rights reserved.