searchCow method Null safety
- BuildContext context,
- String keyword
키워드로 소를 검색합니다.
Implementation
Future<SearchCowResult> searchCow(BuildContext context, String keyword) async {
CowState cowState = Provider.of<CowState>(context, listen: false);
List<String> splittedKeyword = keyword.split('');
if (isKorean(keyword)) splittedKeyword = splitJASO(keyword);
List<Cow> cows = cowState.cows.where((cow) {
bool hasMatch = false;
if (isKorean(keyword)) {
List<String> splittedName = splitJASO(cow.name);
List<String> splittedMemo = splitJASO(cow.memo);
String _keyword = splittedKeyword.join('');
String _name = splittedName.join('');
String _memo = splittedMemo.join('');
hasMatch = _name.startsWith(_keyword) || _memo.startsWith(_keyword);
}
// var pos = cow.managementNumber.lastIndexOf('0');
// String _managementNumber = (pos != -1) ? cow.managementNumber.substring(0, pos) : cow.managementNumber;
return cow.managementNumber.startsWith(keyword) || cow.memo.contains(keyword) || cow.name.contains(keyword) || hasMatch;
}).toList();
return SearchCowResult(cows: cows);
}