Flutter context extension

Created At: 2023-12-31 11:09:33 Updated At: 2024-01-03 08:44:19

Did you ever wonder how to get the context easily like GetX and use the properties like size, height, width, MediaQuery, theme and get platformBrightness?

Here is the complete guide for. Actually it's pretty easy. There's a feature in Flutter called extension methods.

We will start by writting extension and then a method name and then using on and then actual thing you want to extend.

Here our method name is  ContextExt and extending on BuildContext. Then within the method we have getters for Dark mode and Light Mode

And from our UI or presentation layer, we are calling the context and checking on the getters.

Learn about Riverpod and clean architecture with an e-commerce app

Comment

Add Reviews