Last active
May 19, 2021 09:26
-
-
Save rozd/2bfda64c87e001a15f8cd6b76d9e9678 to your computer and use it in GitHub Desktop.
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
import 'package:flutter/widgets.dart'; | |
// MARK: - Iterable Extensions | |
extension FlutterishIterable<T> on Iterable<T> { | |
List<Widget> toWidgets({ | |
required Widget Function(T element) itemBuilder, | |
Widget Function()? separatorBuilder | |
}) { | |
if (separatorBuilder == null) { | |
return this.map((e) => itemBuilder(e)).toList(); | |
} | |
return this.cast<T?>() | |
.expand((e) => e == this.last ? [e] : [e, null]) | |
.map((e) => e != null ? itemBuilder(e) : separatorBuilder()) | |
.cast<Widget>() | |
.toList(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment