티스토리 뷰
startsWith 메소드를 활용해 다중 조건을 처리할 경우, 코드가 지저분해 질 수 있습니다.
아래는 예시코드입니다.
if(
request.url.startsWith('https://www.moducbt.com/') ||
request.url.startsWith('https://moducbt.com/') ||
request.url.startsWith('https://kauth.kakao.com/') ||
request.url.startsWith('https://accounts.kakao.com/') ||
request.url.startsWith('https://accounts.google.com/')
) {
return NavigationDecision.navigate;
}
간단한 유틸 함수를 만들어 반복되는 코드를 제거할 수 있습니다.
아래는 예시코드입니다.
bool checkAllowUrl({required String url}) {
final List<String> allowUrls = [
'https://www.moducbt.com/',
'https://moducbt.com/',
'https://kauth.kakao.com/',
'https://accounts.kakao.com/',
'https://accounts.google.com/',
];
return allowUrls.any((e) {
return url.startsWith(e);
});
}
...
if (checkAllowUrl(url: request.url)) {
return NavigationDecision.navigate;
}
감사합니다
댓글
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- TS
- cbt
- 전기기기
- fakerjs
- 산업안전기사 실기
- 전기기사필기
- 게더타운
- React
- 개더타운
- JavaScript
- dummydata
- zep
- 전기기사실기CBT
- 산안기 합격률
- 전기기사 필기
- 전자기학
- nextjs
- 산업안전기사
- 모두CBT
- TypeScript
- shortid
- 전기기사
- KEC반영
- 실기CBT
- 전력공학
- 전기기사실기단답
- 게더타운맵
- 전기공사기사
- 전기산업기사
- gathertown
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함