Skip to content

Instantly share code, notes, and snippets.

@Diaga
Last active November 17, 2022 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Diaga/452cd526f10dc248348f9f3b6f108c54 to your computer and use it in GitHub Desktop.
Save Diaga/452cd526f10dc248348f9f3b6f108c54 to your computer and use it in GitHub Desktop.
use consumer widget for con con getter

use consumer widget for con con getter

Created with <3 with dartpad.dev.

void main() async {
final tableWidget = TableWidget();
print(tableWidget.build());
}
// Con Con DepController
class DepController<T> {
T instance;
DepController(T Function() builder) : instance = builder();
T call() {
return instance;
}
}
// Con con Controller class
class Controller {}
// Custom UI controller
class TableController extends Controller {
void doStuff() {}
}
// Con con Consumer Widget class
class ConsumerWidget<T extends Controller> extends Widget {
final DepController? _depController;
ConsumerWidget({Key? key, DepController? depController}) : _depController = depController;
T get controller {
return _depController!.call();
}
}
class TableWidget extends ConsumerWidget<TableController> {
TableWidget()
: super(depController: DepController(() {
return TableController();
}));
Widget build() {
// Use controller
controller.doStuff();
return ConsumerWidget();
}
}
// Ignore
class Key {}
class Widget {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment