Want to get size of screen in Flutter app? You can use the MediaQuery class, along with the associated MediaQueryData to determine your screen size and fetch the correct image. You can then compare the MediaQueryData.size member with some predefined screen sizes – this will give you the number of logical pixels.
For example, in the build method of a widget:
1 2 3 4 5 6 7 8 9 10 11 12 13 | class MyWidget extends StatelessWidget { Widget build(BuildContext context) { // retrieve the mediaQuery data final mediaQueryData = MediaQuery.of(context); if (mediaQueryData.size < const Size(100.0, 100.0)) { // build small image. } else { // build big image. } } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.