Flutter & Dart: every() method example
A few examples of using the every() method ( Iterable class) in Dart (and Flutter) . The purpose of this method is to check whether each element of a given iteration satisfies one or more conditions (using a test
bool every(
bool test(
E element
)
)
1. Check that each number in the list is divisible by 3 :
void main() {
var myList = [0, 3, 6, 9, 18, 21, 81, 120];
bool result1 = myList.every((element){
if(element %3 ==0){
return true;
} else {
return false;
}
});
// expectation: true
print(result1);
}
output:
true
2. Check that each name in the list contains the “m” character :
void main() {
var names = ['Obama', 'Trump', 'Biden', 'Pompeo'];
bool hasM = names.every((element) {
if(element.contains('m')) return true;
return false;
});
print(hasM);
}
output:
false
find more details about every() method in the official documentation.
Read More:
- Flutter & Dart Regular Expression Examples
- Flutter & Dart Enumeration Example
- Python: How to Create List by Comprehension (Example Codes)
- File class details (get the file name, size, path, create, etc.)
- Hutool Excel Import & Export Example
- torch.max Example (How to Use)
- Canvas: How to Implement Video Screenshot Function
- Windows Core Audio APIs: How to Progress Loopback Recording and Generate WAV File
- Base64 Image Compression Example
- How to Use Printf in HAL Library
- WCNSS_qcom_cfg.ini WIFI Configuration File Guide
- MultipartFile Upload an Image Example
- Jquery use queue to implement Ajax request queue Simple Example
- Electron: How to Use BrowserWindow to Create a Window
- Android: How to Add Background Music for Activity with Service
- Websocket Front-end Call Example
- Opentelemetry + Jaeger Python Version Cross Service Call Example
- Docker: How to build a rabbitmq image cluster
- Echarts-for-React Example (Install, Import and Effect)
- go sync.Mutex Lock Examples