Adding orElse function to firstWhere method

In case someone came here thanks to google, searching about how to return null if firstWhere found nothing, when your app is Null Safe, use the new method of package:collection called firstWhereOrNull.

import 'package:collection/collection.dart'; // You have to add this manually, for some reason it cannot be added automatically

// somewhere...
MyStuff? stuff = someStuffs.firstWhereOrNull((element) => element.id == 'Cat');

About the method:
https://pub.dev/documentation/collection/latest/collection/IterableExtension/firstWhereOrNull.html

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)