Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create Class.of(context) type of class

I want to create custom class for getting custom textStyles, and i want this class to be static. But i need to pass context too for it. I’ve seen flutter has been using Theme.of(context) or Scaffold.of(context) methods, and i want to make same one like CustomTextStyles.of(context).h1. How this class should be declared ?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The .of method must be handcrafted for each class that uses it. It uses the InheritedWidget mechanism to walk up the context tree to find a widget of an appropriate class. See the docs for InheritedWidget.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading