I am trying to find the best practice for using some casual data.
For example, I have seen in some videos (for example this one), people storing their size at the beginning of their page and sending it as a parameter for every stateless widget they have.
Size size = MediaQuery.of(context).size;
Is it better for the performances (even if it’s a really little) to do like this or is it better to access it every time via MediaQuery.of(context).size ?
>Solution :
calling MediaQuery.of(context) is in order of n where n is the length of your widget tree. so it’s not that bad for most cases. also using MediaQuery.of(context) and not passing along constructors makes your code cleaner. but your widgets should not depend on the size of the screen. in most cases widgets like Flex, Expanded, FitedBox and .. can help you achieve this.
