'Flutter 2: Best practice using/store the size of the phone

I am trying to find a 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;

enter image description here

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 1:[1]

the LayoutBuilder widget could be an alternative. It passes the constraint that belongs to the parent widget, rebuilds if the constraints change. I think it is a cooler solution :D

https://api.flutter.dev/flutter/widgets/LayoutBuilder-class.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 eskimetalci