Here is another way:
var chunks = [];
int chunkSize = 2;
for (var i = 0; i < letters.length; i += chunkSize) {
chunks.add(letters.sublist(i, i+chunkSize > letters.length ? letters.length : i + chunkSize));
}
return chunks;
Run it on dartpad
More Related Contents:
- Sort a list of objects in Flutter (Dart) by property value
- My async call is returning before list is populated in forEach loop
- How do you split a list into evenly sized chunks?
- How do I split a list into equally-sized chunks?
- Unhandled Exception: InternalLinkedHashMap’ is not a subtype of type ‘List
- How can I delete duplicates in a Dart List? list.distinct()?
- Splitting a list of integers into a list of positive integers and a list of negative integers
- In Dart, what’s the difference between List.from and .of, and between Map.from and .of?
- List.shuffle() in Dart?
- How to count items’ occurence in a List
- The argument type ‘String’ can’t be assigned to the parameter type ‘Uri’
- After updating cloud firestore: The operator ‘[]’ isn’t defined for the type ‘Object’. Try defining the operator ‘[]’
- Adding a splash screen to Flutter apps
- How to refresh an AlertDialog in Flutter?
- How to add a ListView to a Column in Flutter?
- Python split string into multiple string [duplicate]
- How to debounce Textfield onChange in Dart?
- How can I dismiss the on screen keyboard?
- How to clone or copy a list in kotlin
- How do I split a string into a list of words?
- Intersection and union of 2 lists
- Difference between a Seq and a List in Scala
- XPath 1.0 to find if an element’s value is in a list of values
- R: Print list to a text file
- Add or remove an entry from a List type attribute in a DynamoDB table item
- Usage of FutureBuilder with setState
- How to save and download text file in Flutter web application
- Flutter – How to download files in WebView?
- how to download/create pdf through webview in flutter
- Recursive Prolog predicate for reverse / palindrome