본문 바로가기
개발/Flutter

if (contain('')) 은 true이다.

by dev_caleb 2022. 8. 10.
728x90

이걸 생각 못하고 있었는데,, 그래서 

  if(searchTextEditController.text.isEmpty){
  searchCurrencyList.value = currencyList;
} else{
  searchCurrencyList.value = currencyList.where((e) => e.countryName.contains(searchTextEditController.text)).toList();
  }

이 코드를 아래와 같이 간단하게 변경할 수 있었다.

어차피 contain(searchTextEditController.text)는 전체를 반환하기 때문에 굳이 if로 나눌 필요가 없었던 것이었다.

 

searchCurrencyList.value = currencyList
    .where((e) => e.countryName.contains(searchTextEditController.text))
    .toList();
728x90