Home > OS >  Flutter 2: Best practice using/store the size of the phone
Flutter 2: Best practice using/store the size of the phone

Time:02-01

I am trying to find the best practice for using some casual data.

For example, I have seen in some videos (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 ?

CodePudding user response:

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.

  •  Tags:  
  • Related