I have an Android 🤖 dev background. So when I started to write in Flutter there were, of course, things that I could do in Kotlin but there were not possible in Dart. I’ve started to write my own extension that could bring a little bit of that back, but also others that help me in day to day coding.
This will be a couple of them. Let me know what do you think and maybe if you have your own and would like to share them in comments that would be great 😃
So in Kotlin you write let/apply/also/run etc. almost all the time. So what I came up with are implementations of let and also.
extension KotlinExt<T> on T {
A let<A>(A Function(T) f) => f(this);
T also(void Function(T) f) {
f(this);
return this;
}
}
In BlocListener you could do:
listener: (context, state) {
state.dialogError?.let((it) => showErrorDialog(it, context));
},
#extension #flutter #utilities