Created with <3 with dartpad.dev.
Last active
November 18, 2022 09:30
-
-
Save Diaga/a31751b8fbc9600f31e5c415d06d47ff to your computer and use it in GitHub Desktop.
dep map
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() { | |
} | |
// Do not have to define separate depController fields | |
class TableWidget extends ConsumerWidget { | |
TableWidget(String arg) : super(depMap: { | |
'textController': Dep(() {return TextController(arg); }), | |
'scrollController': Dep(() {return ScrollController(); }), | |
'tableController': Dep(() {return TableController(); }) | |
}); | |
TextController get textController { | |
return depContainer.textController; | |
} | |
ScrollController get scrollController { | |
return depContainer.scrollController; | |
} | |
TableController get tableController { | |
return depContainer.tableController; | |
} | |
} | |
class ConsumerWidget { | |
ConsumerWidget({Map? depMap}) : | |
depContainer = ConsumerDepContainer(depMap); | |
late final dynamic depContainer; | |
} | |
class ConsumerDepContainer { | |
late Map<String, Dep> _data; | |
ConsumerDepContainer(Map? data) { | |
_data = {}; | |
data?.forEach((k, v) => _data[Symbol(k).toString()] = v); | |
} | |
@override | |
dynamic noSuchMethod(Invocation inv) { | |
if (inv.isGetter) { | |
final res = _data[inv.memberName.toString()]; | |
if (res != null) { | |
return res(); | |
} else { | |
super.noSuchMethod(inv); | |
} | |
} | |
if (inv.isSetter) { | |
_data[inv.memberName.toString().replaceAll('=', '')] = inv.positionalArguments.first; | |
} else { | |
super.noSuchMethod(inv); | |
} | |
} | |
} | |
class Dep { | |
Dep(Function ftn) {} | |
call() {} | |
} | |
// Ignore | |
class ScrollController {} | |
class TextController { | |
TextController(String? arg); | |
} | |
class TableController {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment