-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create prefer-iterable-in-flutter.dart
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
tipsandtricks/prefer-iterable-in-flutter/prefer-iterable-in-flutter.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// π¦ Twitter https://twitter.com/vandadnp | ||
// π΅ LinkedIn https://linkedin.com/in/vandadnp | ||
// π₯ YouTube https://youtube.com/c/vandadnp | ||
// π Free Flutter Course https://linktr.ee/vandadnp | ||
// π¦ 11+ Hours Bloc Course https://youtu.be/Mn254cnduOY | ||
// πΆ 7+ Hours MobX Course https://youtu.be/7Od55PBxYkI | ||
// π¦ 8+ Hours RxSwift Coursde https://youtu.be/xBFWMYmm9ro | ||
// π€ Want to support my work? https://buymeacoffee.com/vandad | ||
|
||
Future<int> doHeavyComputation(int index) => Future.delayed( | ||
const Duration(seconds: 1), | ||
() { | ||
'Iteration ${index + 1}'.log(); | ||
return index; | ||
}, | ||
); | ||
|
||
Future<void> testIt() async { | ||
for (final future in Iterable.generate(10) | ||
.map( | ||
(index) => doHeavyComputation( | ||
index, | ||
), | ||
) | ||
.take(2)) { | ||
final result = await future; | ||
result.log(); | ||
} | ||
} |