Created with <3 with dartpad.dev.
Created
November 18, 2022 08:44
-
-
Save Diaga/563c6f76777d8c4ba215bb040f6eb0f1 to your computer and use it in GitHub Desktop.
dep extension
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
void main() { | |
final w = ConsumerWidget(); | |
print(w.controller); | |
} | |
class ConsumerWidget { | |
TableController get controller { | |
try { | |
print(controller.check); | |
} finally { | |
print("ok"); | |
} | |
return controller.dep(TableController()); | |
} | |
ConsumerWidget() {} | |
void build() { | |
} | |
} | |
class TableController extends Controller { | |
} | |
extension DepExtension<T extends Controller> on T { | |
String get check { | |
return "check"; | |
} | |
T dep(T val) { | |
return val; | |
} | |
} | |
class DepFunction on T Function() { | |
T get dep { | |
return this(); | |
} | |
} | |
class Dep<T> { | |
final T Function() builder; | |
Dep(T Function() builder) : this.builder = builder; | |
T call() { | |
return this.builder(); | |
} | |
} | |
// Ignore | |
class Controller { | |
static String val = "ok"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment